next up previous contents
Next: A DD Consumer Up: Example Programs Previous: Example Programs

A DD Producer Process

The listing below is a producer that first creates the DD system (if it doesn't exist, attaches to the INPUT_FIFO and then injects 100 event into the DD system. If there are no buffers available, the process falls asleep ( FMODE_SLEEP) until one has become free.

#include <dd_sys.h>
#include <dd_user.h>

 
main()

{

int i, j, len, *p;

int mode, reqcnt, prescale, wait,ctl[4];

mode = FMODE_ALL;

wait = DD_WAIT_SLEEP;

prescale = 1;

for (i=0;i<4;i++)

ctl[i] = -1;

if ( (status = dds_create() ) != 0 ) {

printf(" dds_create: status returned %d \n" ,status);

exit(1);

}

if ( (status = ddu_init(``INPUT'',mode,prescale,wait,ctl)) != 0 ) {

printf("ddu_init status %d \n",status);

exit(1);

}

len = 1000;

for (i=0; i<100; i++) {

status = ddu_req_fev(len, &fev);

if (status == 0){

p = fev.p2da;

fev.len = len;

fev.ctlw1 = i%4+1;

fev.ctlb1 = rand() & 3;

fev.ctlw2 = -1;

fev.ctlb2 = -1;

for (j=0; j<len; j++) {

*p++ = j;

if ( ( status = ddu_put_fev(fev) ) != 0) {

printf("ddu_put_fev: status returned %d \n",status);

break;

}

} else {

printf("ddu_req_fev: status returned %d \n",status);

break;

}

}

ddu_close();

printf("dd cleaned up\n");

exit(0);

}



Online software development
Thu Mar 14 10:35:53 EST 1996