Annotation of os2sdk/demos/examples/vioreg/access.c, revision 1.1.1.1

1.1       root        1: /* This routine is started in a DosStartSession call from REGISTER.EXE. */
                      2: /* It accesses the shared memory allocated in REGISTER, and prints the */
                      3: /* contents of the counters being incremented by the viosubsystem      */
                      4: /* replacement routine, REPLACE, found in the VIOROUT dll.             */
                      5: /*                                                                     */
                      6: /* Created by Microsoft Corp. 1988                                     */
                      7: 
                      8: #define INCL_DOSPROCESS
                      9: #define INCL_DOSMEMMGR
                     10: #define INCL_DOSSEMAPHORES
                     11: 
                     12: #include <os2def.h>
                     13: #include <bsedos.h>
                     14: #include <stdio.h>
                     15: #include "share.h"      /* Common declarations between processes */
                     16: 
                     17: main()
                     18: {   SEL Selector;                  /* Shared memory selector */
                     19:     struct ShareRec far *SmemPtr;   /* Shared memory layout, defined in Share.h */
                     20:     unsigned rc;                   /* Return code */
                     21:     int calls;
                     22:     int total;
                     23: 
                     24:     /* Access shared memory allocated in REGISTER.EXE */
                     25:     /* This session is started after the memory has been allocated, so
                     26:        no need to loop waiting for allocation */
                     27:     if (rc = DosGetShrSeg(SHRSEGNAME, &Selector)){
                     28:        printf(" Illegal share segment.\n");
                     29:        DosExit(EXIT_PROCESS,0);
                     30:        }
                     31: 
                     32:     /* Get far pointer from 16 bit selector */
                     33:     SmemPtr = (struct ShareRec far *)MAKEP(Selector,0);
                     34: 
                     35:     printf("\n");
                     36:     printf("\n");
                     37:     printf("%60s\n", "ACCESSING SHARED MEMORY REPLACEMENT ROUTINE IS UPDATING");
                     38:     printf("\n");
                     39:     printf(" Type CTRL-C to quit\n");
                     40:     printf("\n");
                     41:     printf("\n");
                     42:     while (1 ) {
                     43:        /* Interleave with replacement routine, REPLACE */
                     44:        DosSemWait((HSEM)&(SmemPtr->updated), WAITFOREVER);
                     45: 
                     46:        DosSemRequest((HSEM)&(SmemPtr->mutexsem), WAITFOREVER);
                     47:        /* Access counter contents */
                     48:        calls = SmemPtr->count;
                     49:        total = SmemPtr->totalength;
                     50:        DosSemClear((HSEM)&(SmemPtr->mutexsem));
                     51: 
                     52:        DosSemSet((HSEM)&(SmemPtr->updated));
                     53: 
                     54:        /* Print counter contents */
                     55:        printf("%s%d%s%d\r", "Number of calls to VIOWRTTTY = ", calls,
                     56:               " Total number of bytes written = ", total);
                     57:        }
                     58: 
                     59: }

unix.superglobalmegacorp.com

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