|
|
Microsoft OS/2 SDK 03-01-1988
/* This routine is the viosubsystem replacement routine for */
/* VioWrtTTy. It does nothing but increment counters in shared */
/* memory that have been allocated in REGISTER. Access to the shared */
/* memory is interleaved with ACCESS, which prints the contents of the */
/* counters. */
/* */
/* Created by Microsoft Corp. 1988 */
#define INCL_DOSSEMAPHORES
#define INCL_DOSMEMMGR
#include <os2def.h>
#include <bsedos.h>
#include <stdio.h>
#include "share.h" /* Common declarations between processes */
int _acrtused=0; /* _acrtused must be declared in one of the modules */
/* of the dll. The C compiler generates this symbol */
/* as an extern to ensure that the runtime library */
/* startup module crt0 will be pulled in by the */
/* linker. Declaring _acrtused will keep this */
/* unwanted code out. */
/* The VIO router places the VioWrtTTy parameters on the stack, along */
/* with the registered routine's (VioWrtTTy) address and index, the */
/* entry point in the VIO router, the caller's DS and the dynamic */
/* link entry point. The replacement router places the contents of */
/* registers BP and DI on the stack, and then copies the parameters */
/* on the stack again. Declaring the replacement routine as pascal */
/* allows proper access to the parameters. */
int APIENTRY REPLACE(Charstr,length, handle)
PCH Charstr; /* These three are the parameters for */
USHORT length; /* VioWrtTTy */
SHANDLE handle;
{ SEL Selector; /* Shared memory selector */
struct ShareRec far *SmemPtr; /* Shared memory layout, described
in Share.h */
int rc; /* Return code */
DosGetShrSeg(SHRSEGNAME, &Selector);
/* Get a far pointer from a 16 bit selector */
SmemPtr = (struct ShareRec far *)MAKEP(Selector,0);
DosSemRequest((HSEM)&(SmemPtr->mutexsem), WAITFOREVER);
SmemPtr->count++;
/* Increment the total length, using the length parameter */
SmemPtr->totalength += length;
/* Updated is set in ACCESS, and cleared here, creating the
interleaving */
DosSemClear((HSEM)&(SmemPtr->updated));
DosSemClear((HSEM)&(SmemPtr->mutexsem));
/* Must use DosFreeSeg in order to decrement the reference
counter to the shared memory segment. The segment will
not be deallocated until the reference count is 0, this
will not happen because DosGetShrSeg increments the reference
counter, and there is one DosGetShrSeg call in REGISTER. */
DosFreeSeg(Selector);
/* Returning -1 causes the VIO router to invoke the replaced
routine, i.e. VioWrtTTy */
return(-1);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.