Annotation of os2sdk/demos/examples/share/shrchild.c, revision 1.1.1.2

1.1       root        1: /*
1.1.1.2 ! root        2:  * This is the child process exec'd asynchronously from share.c.
        !             3:  *
        !             4:  * Created by Microsoft Corp. 1986
1.1       root        5:  */
                      6: 
1.1.1.2 ! root        7: #define INCL_DOSMEMMGR
        !             8: #define INCL_DOSSEMAPHORES
        !             9: #define INCL_DOSFILEMGR
        !            10: #define INCL_DOSPROCESS
        !            11: 
        !            12: #include <os2def.h>
        !            13: #include <bsedos.h>            /* necessary whenever doscalls are made */
1.1       root       14: #include "share.h"             /* common shared memory declarations */
                     15: 
                     16: main()
                     17: {
1.1.1.2 ! root       18:        SEL                     Selector;
1.1       root       19:        unsigned                rc;             /* return code */
1.1.1.2 ! root       20:        USHORT                  nBytes;
1.1       root       21:        char                    c;
                     22:        struct ShareRec         *SmemPtr;       /* shared memory pointer */
                     23: 
                     24:        /* get selector to the shared memory segment defined in parent */
                     25: 
1.1.1.2 ! root       26:        if (rc = DosGetShrSeg( (PSZ) SHRSEGNAME,
        !            27:                                &Selector ))  {
        !            28:                DosExit(EXIT_PROCESS, 0);
1.1       root       29:        }
                     30: 
                     31:        /* Get a far pointer from a 16 bit selector */
                     32: 
1.1.1.2 ! root       33:        SmemPtr = (struct ShareRec *) MAKEP(Selector, 0);
1.1       root       34:        
                     35:        for (;;) {
                     36: 
                     37:            /* block if buffer empty */
1.1.1.2 ! root       38:            DosSemWait((HSEM)&(SmemPtr->emptysem), WAITFOREVER);
1.1       root       39: 
1.1.1.2 ! root       40:            /* mutual exclusion on buffer pointers and semaphores */
        !            41:            DosSemRequest((HSEM)&(SmemPtr->mutexsem), WAITFOREVER);
1.1       root       42:            c = SmemPtr->CircBuffer[SmemPtr->tail];     /* get next char */
                     43:            SmemPtr->tail++;                /* step pointer */
                     44:            SmemPtr->tail %= CIRCBUFSIZE;   /* wrap at end  */
                     45:            if (SmemPtr->tail == SmemPtr->head)
1.1.1.2 ! root       46:                DosSemSet((HSEM)&(SmemPtr->emptysem)); /* indicate buf empty */
        !            47:            DosSemClear((HSEM)&(SmemPtr->fullsem));    /* indicate buf !full */
        !            48:            DosSemClear((HSEM)&(SmemPtr->mutexsem));
1.1       root       49: 
1.1.1.2 ! root       50:            DosWrite( 1, (PVOID) &c, 1, &nBytes );     /* display next char */
        !            51:            DosSleep(1000L);    /* max 1 per sec to demo buffering & sems */
1.1       root       52:        }
                     53: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.