|
|
1.1 ! root 1: /* ! 2: * This is the child process exec'd asynchronously from the child.c. ! 3: */ ! 4: ! 5: #include <doscalls.h> /* necessary whenever doscalls are made */ ! 6: #include "share.h" /* common shared memory declarations */ ! 7: ! 8: main() ! 9: { ! 10: unsigned Selector; ! 11: unsigned rc; /* return code */ ! 12: unsigned nBytes; ! 13: char c; ! 14: struct ShareRec *SmemPtr; /* shared memory pointer */ ! 15: ! 16: /* get selector to the shared memory segment defined in parent */ ! 17: ! 18: if (rc = DOSGETSHRSEG( (char *) SHRSEGNAME, ! 19: (unsigned *) &Selector )) { ! 20: DOSEXIT(1, 0); ! 21: } ! 22: ! 23: /* Get a far pointer from a 16 bit selector */ ! 24: ! 25: SmemPtr = (struct ShareRec *) GETSEGPTR(Selector, 0); ! 26: ! 27: for (;;) { ! 28: ! 29: /* block if buffer empty */ ! 30: DOSSEMWAIT((long)&(SmemPtr->emptysem), WAITFOREVER); ! 31: ! 32: /* mutual exclusion on buffer pointers */ ! 33: DOSSEMREQUEST((long)&(SmemPtr->mutexsem), WAITFOREVER); ! 34: c = SmemPtr->CircBuffer[SmemPtr->tail]; /* get next char */ ! 35: SmemPtr->tail++; /* step pointer */ ! 36: SmemPtr->tail %= CIRCBUFSIZE; /* wrap at end */ ! 37: if (SmemPtr->tail == SmemPtr->head) ! 38: DOSSEMSET((long)&(SmemPtr->emptysem)); ! 39: DOSSEMCLEAR((long)&(SmemPtr->mutexsem)); ! 40: ! 41: DOSSEMCLEAR((long)&(SmemPtr->fullsem)); ! 42: ! 43: DOSWRITE( 1, (char *) &c, 1, &nBytes ); /* display next char */ ! 44: DOSSLEEP(1000L); /* max 1 per sec to demo buffering & sems */ ! 45: } ! 46: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.