Annotation of os2sdk/demos/examples/vioreg/viosub.c, revision 1.1

1.1     ! root        1: /* This routine is the viosubsystem replacement routine for           */
        !             2: /* VioWrtTTy.  It does nothing but increment counters in shared        */
        !             3: /* memory that have been allocated in REGISTER.  Access to the shared  */
        !             4: /* memory is interleaved with ACCESS, which prints the contents of the */
        !             5: /* counters.                                                          */
        !             6: /*                                                                    */
        !             7: /*   Created by Microsoft Corp. 1988                                  */
        !             8: 
        !             9: #define INCL_DOSSEMAPHORES
        !            10: #define INCL_DOSMEMMGR
        !            11: 
        !            12: #include <os2def.h>
        !            13: #include <bsedos.h>
        !            14: #include <stdio.h>
        !            15: #include "share.h"    /* Common declarations between processes */
        !            16: 
        !            17: int _acrtused=0;  /* _acrtused must be declared in one of the modules  */
        !            18:                  /* of the dll. The C compiler generates this symbol  */
        !            19:                  /* as an extern to ensure that the runtime library   */
        !            20:                  /* startup module crt0 will be pulled in by the      */
        !            21:                  /* linker.  Declaring _acrtused will keep this       */
        !            22:                  /* unwanted code out.                                */
        !            23: 
        !            24: /* The VIO router places the VioWrtTTy parameters on the stack, along  */
        !            25: /* with the registered routine's (VioWrtTTy) address and index, the    */
        !            26: /* entry point in the VIO router, the caller's DS and the dynamic      */
        !            27: /* link entry point.  The replacement router places the contents of    */
        !            28: /* registers BP and DI on the stack, and then copies the parameters    */
        !            29: /* on the stack again. Declaring the replacement routine as pascal    */
        !            30: /* allows proper access to the parameters.                            */
        !            31: 
        !            32: 
        !            33: int APIENTRY REPLACE(Charstr,length, handle)
        !            34: PCH Charstr;        /* These three are the parameters for        */
        !            35: USHORT length;      /* VioWrtTTy                                 */
        !            36: SHANDLE handle;
        !            37: 
        !            38: {    SEL Selector;                 /* Shared memory selector */
        !            39:      struct ShareRec far *SmemPtr;  /* Shared memory layout, described
        !            40:                                       in Share.h  */
        !            41:      int rc;                       /* Return code */
        !            42: 
        !            43:      DosGetShrSeg(SHRSEGNAME, &Selector);
        !            44: 
        !            45:      /* Get a far pointer from a 16 bit selector */
        !            46:      SmemPtr = (struct ShareRec far *)MAKEP(Selector,0);
        !            47: 
        !            48:      DosSemRequest((HSEM)&(SmemPtr->mutexsem), WAITFOREVER);
        !            49:      SmemPtr->count++;
        !            50: 
        !            51:      /* Increment the total length, using the length parameter */
        !            52:      SmemPtr->totalength += length;
        !            53: 
        !            54:      /* Updated is set in ACCESS, and cleared here, creating the
        !            55:        interleaving  */
        !            56:      DosSemClear((HSEM)&(SmemPtr->updated));
        !            57:      DosSemClear((HSEM)&(SmemPtr->mutexsem));
        !            58: 
        !            59:      /* Must use DosFreeSeg in order to decrement the reference
        !            60:        counter to the shared memory segment.  The segment will
        !            61:        not be deallocated until the reference count is 0, this
        !            62:        will not happen because DosGetShrSeg increments the reference
        !            63:        counter, and there is one DosGetShrSeg call in REGISTER. */
        !            64:      DosFreeSeg(Selector);
        !            65: 
        !            66:      /* Returning -1 causes the VIO router to invoke the replaced
        !            67:        routine, i.e. VioWrtTTy */
        !            68:      return(-1);
        !            69: }

unix.superglobalmegacorp.com

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