File:  [OS/2 SDKs] / os2sdk / demos / examples / vioreg / access.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:11 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/* This routine is started in a DosStartSession call from REGISTER.EXE. */
/* It accesses the shared memory allocated in REGISTER, and prints the	*/
/* contents of the counters being incremented by the viosubsystem	*/
/* replacement routine, REPLACE, found in the VIOROUT dll.		*/
/*									*/
/* Created by Microsoft Corp. 1988					*/

#define INCL_DOSPROCESS
#define INCL_DOSMEMMGR
#define INCL_DOSSEMAPHORES

#include <os2def.h>
#include <bsedos.h>
#include <stdio.h>
#include "share.h"	 /* Common declarations between processes */

main()
{   SEL Selector;		    /* Shared memory selector */
    struct ShareRec far *SmemPtr;   /* Shared memory layout, defined in Share.h */
    unsigned rc;		    /* Return code */
    int calls;
    int total;

    /* Access shared memory allocated in REGISTER.EXE */
    /* This session is started after the memory has been allocated, so
       no need to loop waiting for allocation */
    if (rc = DosGetShrSeg(SHRSEGNAME, &Selector)){
	printf(" Illegal share segment.\n");
	DosExit(EXIT_PROCESS,0);
	}

    /* Get far pointer from 16 bit selector */
    SmemPtr = (struct ShareRec far *)MAKEP(Selector,0);

    printf("\n");
    printf("\n");
    printf("%60s\n", "ACCESSING SHARED MEMORY REPLACEMENT ROUTINE IS UPDATING");
    printf("\n");
    printf(" Type CTRL-C to quit\n");
    printf("\n");
    printf("\n");
    while (1 ) {
	/* Interleave with replacement routine, REPLACE */
	DosSemWait((HSEM)&(SmemPtr->updated), WAITFOREVER);

	DosSemRequest((HSEM)&(SmemPtr->mutexsem), WAITFOREVER);
	/* Access counter contents */
	calls = SmemPtr->count;
	total = SmemPtr->totalength;
	DosSemClear((HSEM)&(SmemPtr->mutexsem));

	DosSemSet((HSEM)&(SmemPtr->updated));

	/* Print counter contents */
	printf("%s%d%s%d\r", "Number of calls to VIOWRTTTY = ", calls,
	       " Total number of bytes written = ", total);
	}

}

unix.superglobalmegacorp.com

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