Пример #1
0
/*  lockncbpool - lock pool of async ncbs for exclusive access
*/
void
lockncbpool(void)
{
#ifndef REALMODE
#ifdef OS2
  register int rc;

  if (rc = DosSemRequest ((unsigned long FAR *) &async_ncb_pool_sem, (long) -1))
    {
#ifdef DEBUG
      fprintf(stderr, "Bad semaphore request (%d)\n", rc);
#endif
      exit ( rc );
    }
#else	    // NT
    DWORD waitResult;

    waitResult = WaitForSingleObject (async_ncb_pool_sem, 100000);
    if ( waitResult < 0 ) {
	fprintf(stderr, "Semaphore wait failed (%d)\n", GetLastError());
	exit ( GetLastError() );
    }
    else if (waitResult == WAIT_TIMEOUT)  {
	fprintf(stderr, "NCB Pool lock timed-out");
	exit ( 0 );
    }
    else if (waitResult == WAIT_ABANDONED)  {
	fprintf(stderr, "NCB Pool lock wait abandoned");
	exit ( 0 );
    }

#endif
#endif
}
Пример #2
0
static void
mousehandler()
{
    for (;;) {
	MOUEVENTINFO	m;
	unsigned short	status;
	clock_t		start;

#if 0
	if (MouGetDevStatus((PUSHORT) &status, mousenum) != 0
	    ||
	    (status & (MOUSE_UNSUPPORTED_MODE | MOUSE_DISABLED))
	) {
	    hidemouse();
	    (void) MouClose(mousenum);
	    DosExit(EXIT_THREAD, 0);
	}
#endif
	status = MOU_WAIT;
	MouReadEventQue((PMOUEVENTINFO) &m, (PUSHORT) &status, mousenum);
	/*
	 * If we don't get the control semaphore immediately,
	 * we do nothing. Delayed responses to mouse button
	 * presses could be confusing.
	 */
#if 0
	start = clock();
#endif
	if (DosSemRequest(control, SEM_IMMEDIATE_RETURN) != 0)
	    continue;
#if 0
	if (clock() != start) {
	    (void) fprintf(stderr, "mouse thread: %d\n", __LINE__);
	    DosSemClear(control);
	    continue;
	}
#endif
	/*
	 * Start of critical section.
	 */
	if (++keystrokes >= PSVKEYS)
	    lastevent = clock();
	if (State == NORMAL &&
		(m.fs & (MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN))) {
	    hidemouse();
	    mouseclick(m.row, m.col);
	    showmouse();
	}
	/*
	 * End of critical section.
	 */
	DosSemClear(control);
    }
}
VOID main(VOID)
{
   USHORT usReturn_Code;           /*  Dos function Return Code              */

   PSZ    pszName = SHARENAME;              /*  Shareable memory block name  */
   SEL    selMem_Selector;                  /*  Receive Segment selector     */

   PSZ     pszSemName = SEMNAME;            /*  System semaphore name        */
   HSEM    hsemSemHandle;                   /*  System semaphore Handle      */

   WATCH FAR * Watch_Ptr;          /*  WATCH pointer                         */

                                   /* Get Access to Shareable memory Block   */
   usReturn_Code = DosGetShrSeg(pszName, & selMem_Selector);

   if (usReturn_Code == 0) {
      Watch_Ptr = (WATCH FAR *) MAKEP(selMem_Selector,0);

      DosOpenSem( & hsemSemHandle,          /*  Open System semaphore        */
                  pszSemName);

      DosSemRequest(hsemSemHandle,          /*  Waits for shared resources   */
                    SEM_INDEFINITE_WAIT);

                            /* Restore Init value count if WATCHDOG enabled  */
      if (Watch_Ptr->Flag & ENABLE_MASK)
         Watch_Ptr->Counter = Watch_Ptr->Counter_Init_Value ;

      DosSemClear(hsemSemHandle);             /*  Release  shared resources  */

      DosFreeSeg(selMem_Selector);            /*  Freeing Shared memory      */

   } else {
      DosBeep(262,250);DosBeep(330,250);DosBeep(392,250);DosBeep(494,250);
      DosBeep(392,250);DosBeep(330,250);DosBeep(262,250);

#ifdef DEBUG
      printf("\n -*-*- STARTTPS Error Code %04x -*-*-\n",usReturn_Code);
      printf("  -*-    WatchDog not Started    -*-\n");
#endif

   } /* endif */

   DosExit((USHORT) 0,usReturn_Code);         /*  Exit Process              */

} /* end of main program */
Пример #4
0
/*
 * This function handles automatic buffer preservation. It runs in its
 * own thread, which is only awake when keystrokes >= PSVKEYS and the
 * main thread is waiting for keyboard input. Even then, it spends
 * most of its time asleep.
 */
static void FAR
psvhandler()
{
    for (;;) {
	long	sleeptime;

	DosSemWait(psvsema, SEM_INDEFINITE_WAIT);
	DosSemRequest(control, SEM_INDEFINITE_WAIT);
	/*
	 * Start of critical section.
	 */
	if (keystrokes < PSVKEYS) {
	    sleeptime = 0;
	    /*
	     * If we haven't had at least PSVKEYS
	     * keystrokes, psvsema should be set.
	     */
	    DosSemSet(psvsema);
	} else if ((sleeptime = (long) Pn(P_preservetime) * 1000 -
		      CLK2MS(clock() - lastevent)) <= 0) {
	    /*
	     * If Pn(P_presevetime) seconds haven't yet
	     * elapsed, sleep until they should have - but
	     * NOT within the critical section (!).
	     *
	     * Otherwise do automatic preserve.
	     *
	     * exPreserveAllBuffers() should reset keystrokes to 0.
	     */
	    (void) exPreserveAllBuffers();
	    sleeptime = 0;
	}
	/*
	 * End of critical section.
	 */
	DosSemClear(control);
	/*
	 * Sleep if we have to.
	 */
	if (sleeptime != 0)
	    DosSleep(sleeptime);
    }
}
Пример #5
0
_WCRTLINK int _WCFAR _beginthread( thread_fn *start_address,
                            void _WCFAR *stack_bottom,
                            unsigned stack_size,
                            void _WCFAR *arglist )
/*****************************************************/
{
    TID         tid;
    APIRET      rc;

    DosSemRequest( &data_sem, -1L );
    Routine = start_address;
    Argument = arglist;
    StackBottom = stack_bottom;
    rc = DosCreateThread( begin_thread_helper, (PTID)&tid,
                          (PBYTE)((char _WCFAR *)stack_bottom + stack_size) );
    if( rc != 0 ) {
        DosSemClear( &data_sem );
        return( -1 );
    }
    if( tid > __MaxThreads ) {
        return( -1 );
    }
    return( tid );
}
Пример #6
0
 xType2 ehnConnect(int thisConnect)
{
 char       Work[40];
 int        wasCode;
 unsigned   returnCode=OK,unLength;

 if (thisDB.connecting) 
     DosSemRequest(&thisDB.gate,SEM_INDEFINITE_WAIT);

 thisDB.connecting = TRUE;
 
 DosSemSet(&thisDB.gate);

 if (!thisDB.channel) thisDB.channel = DEFAULT_CHANNEL;
 
 if (debug >= 5000) return(OK);

 if (!thisState->actualCarrierLinked)
 {returnCode=EHNRQSTART(thisDB.channel,commit_mode,MAX_SQL_TEXT);
  if (!returnCode || returnCode==RQ_ALRDY_INIT)
    {xsqlLogPrint("%s connected to AS400 OK.",thisDB.subject);
     returnCode = thisConnect;
     EHNRQSETROWS(200);
     if (!thisSQLstate) 
     {thisSQLstate = malloc(sizeof(struct sqlca));
      memset(thisSQLstate,'\0',sizeof(struct sqlca));
     }
    }
  else
  {xsqlLogPrint("%s Couldn't connect to %s.",thisDB.subject,thisDB.channel);
   xsqlLogPrint("%s EHNRQSTART returned %d.",thisDB.subject,returnCode);
   returnCode   = FALSE;
  }
 }

 thisState->actualCarrierLinked = TRUE;
 thisDB.cursorIneligibility     = SQL_INSERT;

 if ((thisDB.accessMode == DRDA_PC_SUPPORT) ||
     (thisDB.accessMode == DDM_PC_SUPPORT))
 {char connectStatement[200];
 
  if (!thisDB.object)
    {xsqlLogPrint("%s Didn't name an object to connect to.",thisDB.subject);
     returnCode = OK;
    }
  else {sprintf(connectStatement,
    //            "CONNECT TO %s USER DAUGHERJ USING 'BEOBACHT'",
                  "CONNECT TO %s ",
                thisDB.object);
        xsqlLogPrint(connectStatement);
        returnCode=EHNRQCONNECT(connectStatement,NULL,&unLength);
        if (!returnCode || returnCode==RQ_ALRDY_INIT)
           {xsqlLogPrint("%s Connected to %s OK.",
                       thisDB.subject,thisDB.object);
            returnCode = thisConnect;
            thisDB.connected = TRUE;
           }    
        else
        {xsqlLogPrint("%s Couldn't connect to %s.",
                    thisDB.subject,thisDB.object);
         xsqlLogPrint("%s EHNRQCONNECT returned %d.",
                    thisDB.subject,returnCode);
         if (returnCode == 8)
             ehnError(returnCode,"EHNRQCONNECT",thisConnect);
         returnCode   = FALSE;
        }
       }
 } else thisDB.connected = TRUE;

 thisDB.connecting = FALSE;
 DosSemClear(&thisDB.gate);
 return(returnCode);

}  
Пример #7
0
_WCRTLINK void __AccessSemaphore( semaphore_object *obj )
{
    TID tid;

    tid = GetCurrentThreadId();
#if defined( _NETWARE_CLIB )
    if( tid == 0 )
        return;
#endif
    if( obj->owner != tid ) {
#if defined( _M_I86 )
        DosSemRequest( &obj->semaphore, -1L );
#else
  #if !defined( __NETWARE__ )
        if( obj->initialized == 0 ) {
    #if defined( __RUNTIME_CHECKS__ ) && defined( _M_IX86 )
            if( obj == &InitSemaphore ) {
                __fatal_runtime_error( "Bad semaphore lock", 1 );
            }
    #endif
            __AccessSemaphore( &InitSemaphore );
            if( obj->initialized == 0 ) {
    #if defined( __NT__ )
                obj->semaphore = __NTGetCriticalSection();
    #elif defined( __QNX__ )
                __qsem_init( &obj->semaphore, 1, 1 );
    #elif defined( __LINUX__ )
                // TODO: Access semaphore under Linux!
    #elif defined( __RDOS__ )
                obj->semaphore = RdosCreateSection();
    #elif defined( __RDOSDEV__ )
                RdosInitKernelSection(&obj->semaphore);
    #else
                DosCreateMutexSem( NULL, &obj->semaphore, 0, FALSE );
    #endif
                obj->initialized = 1;
            }
            __ReleaseSemaphore( &InitSemaphore );
        }
  #endif
  #if defined( __NETWARE__ )
        while( obj->semaphore != 0 ) {
    #if defined (_NETWARE_CLIB)
            ThreadSwitch();
    #else
            NXThreadYield();
    #endif
        }

        obj->semaphore = 1;
        obj->initialized = 1;
  #elif defined( __NT__ )
        EnterCriticalSection( obj->semaphore );
  #elif defined( __QNX__ )
        __qsem_wait( &obj->semaphore );
  #elif defined( __LINUX__ )
        // TODO: Wait for semaphore under Linux!
  #elif defined( __RDOS__ )
        RdosEnterSection( obj->semaphore );
  #elif defined( __RDOSDEV__ )
        RdosEnterKernelSection( &obj->semaphore );
  #else
        DosRequestMutexSem( obj->semaphore, SEM_INDEFINITE_WAIT );
  #endif
#endif
        obj->owner = tid;
    }
    obj->count++;
}
Пример #8
0
BOOL GetMemoryBitmap (HAB hab)
     {
     SIZEL sizl;
     BITMAPINFOHEADER bmp, bmpQQ;
     RECTL rcl;
     LONG   alBmpFormats[12];
     LONG errorcode;
     int  i, j;
     LONG pm_bytes, li;
     unsigned char _huge *phc;

     /* serialize destroy/create */
     DosSemRequest((HSEM) &cp.ulSemMemPS, SEM_INDEFINITE_WAIT);

     /* set the sizl and rcl values */
     sizl.cx = (LONG) cp.cx;
     sizl.cy = (LONG) cp.cy;
     rcl.xLeft = 0;
     rcl.yBottom = 0;
     rcl.xRight = cp.cx;
     rcl.yTop = cp.cy;

     /* start by assuming 256-color */
     cp.pm_xdots = ((ULONG) cp.cx + 3) & 0xFFFFFFFC;
     cp.pixelshift_per_byte = 0;
     cp.pixels_per_byte   = 1;
     cp.pixels_per_bytem1 = 0;
     cp.cPlanes = 1;
     cp.cBitCount = 8;
     cp.sCurrentPalette = IDD_PAL_VGA256;
     cp.pbmiMemory = &bmiColorTableVGA256;

     if (cp.colors == 16) { /* Wrong guess... */
        cp.cPlanes = 1;
        cp.cBitCount = 4;
        cp.pixelshift_per_byte = 1;
        cp.pm_xdots = (((ULONG) cp.cx + 7) & 0xfffffff8);
        cp.pixels_per_byte = 2;
        cp.pixels_per_bytem1 = 1;
        cp.pm_andmask[0] = 0xf0;
        cp.pm_notmask[0] = 0x0f;
        cp.pm_bitshift[0] = 4;
        cp.pm_andmask[1] = 0x0f;
        cp.pm_notmask[1] = 0xf0;
        cp.pm_bitshift[1] = 0;
        cp.sCurrentPalette = IDD_PAL_VGA16;
        cp.pbmiMemory = &bmiColorTableVGA16;
        }

     if (cp.colors == 2) { /* ... or again ... */
        cp.cPlanes = 1;
        cp.cBitCount = 1;
        cp.pixelshift_per_byte = 3;
        cp.pm_xdots = (((ULONG) cp.cx+31) & 0xffffffe0);
        cp.pixels_per_byte = 8;
        cp.pixels_per_bytem1 = 7;
        cp.pm_andmask[0] = 0x80;
        cp.pm_notmask[0] = 0x7f;
        cp.pm_bitshift[0] = 7;
        for (i = 1; i < 8; i++) {
            cp.pm_andmask[i] = cp.pm_andmask[i-1] >> 1;
            cp.pm_notmask[i] = (cp.pm_notmask[i-1] >> 1) + 0x80;
            cp.pm_bitshift[i] = cp.pm_bitshift[i-1] - 1;
            }
        cp.sCurrentPalette = IDD_PAL_BW;
        cp.pbmiMemory = &bmiColorTableBW;
        }
Пример #9
0
/*
 * inchar() - get a character from the keyboard.
 *
 * Timeout not implemented yet for OS/2.
 */
int
inchar(long mstimeout)
{
    for (;;) {
	KBDKEYINFO k;
	bool_t	mstatus,
		psvstatus;

	flush_output();

	mstatus = (usemouse && State == NORMAL);
	psvstatus = (keystrokes >= PSVKEYS);
	/*
	 * We don't have to give control to any other thread
	 * if neither of these conditions is true.
	 */
	if (mstatus || psvstatus) {
#ifndef NOMOUSE
	    if (mstatus)
		showmouse();
#endif
	    if (psvstatus && DosSemWait(psvsema, SEM_IMMEDIATE_RETURN)
						    == ERROR_SEM_TIMEOUT) {
		/*
		 * If psvsema is set, clear it.
		 */
		DosSemClear(psvsema);
	    }
	    DosSemClear(control);
	}
	/*
	 * Start of non-critical section.
	 *
	 * Wait for character from keyboard.
	 */
	KbdCharIn((PKBDKEYINFO) &k, IO_WAIT, 0);
	/*
	 * End of non-critical section.
	 */
	if (mstatus || psvstatus) {
	    DosSemRequest(control, SEM_INDEFINITE_WAIT);
#ifndef NOMOUSE
	    if (mstatus)
		hidemouse();
#endif
	}
	if (++keystrokes >= PSVKEYS)
	    lastevent = clock();
	/*
	 * Now deal with the keypress information.
	 */
	if ((unsigned char) k.chChar == (unsigned char) 0xe0) {
	/*
	 * It's (probably) a function key.
	 */
	    if (k.chScan == 0x53)
		/*
		 * It's the delete key.
		 */
		return State == NORMAL ? 'x' : '\b';
	     /* else */
	    if (State == NORMAL) {
		/*
		 * Assume it must be a function key.
		 */
		switch (k.chScan) {
		    case 0x3b: return(K_HELP);	  /* F1 key */
		    case 0x47: return(K_HOME);	  /* home key */
		    case 0x48: return(K_UARROW);  /* up arrow key */
		    case 0x49: return(K_PGUP);	  /* page up key */
		    case 0x4b: return(K_LARROW);  /* left arrow key */
		    case 0x4d: return(K_RARROW);  /* right arrow key */
		    case 0x4f: return(K_END);	  /* end key */
		    case 0x50: return(K_DARROW);  /* down arrow key */
		    case 0x51: return(K_PGDOWN)); /* page down key */
		    case 0x52: return(K_INSERT);  /* insert key */
		    default:
			/* just ignore it ... */
			continue;
		}
		/*
		 * If we aren't in command mode, 0xe0
		 * is a perfectly legitimate
		 * character, & we can't really tell
		 * whether or not it's supposed to be
		 * a function key, so we just have to
		 * return it as is.
		 */
	    }
	}
	return (unsigned char) k.chChar;
    }
}
Пример #10
0
void PASCAL init_list ()
{
//       unsigned       rc;
//       USHORT i;
    LPVOID      lpParameter = NULL;
    DWORD       dwThreadId;

//       char   c;


    /*
     * Init Misc
     */
    DosSemSet (vSemSync);
    DosSemSet (vSemMoreData);



    /*
     * Init screen parameters
     */

    GetConsoleScreenBufferInfo( vStdOut,
                                &vConsoleOrigScrBufferInfo );

    vConsoleOrigScrBufferInfo.dwSize.X=
        vConsoleOrigScrBufferInfo.srWindow.Right-
        vConsoleOrigScrBufferInfo.srWindow.Left + 1;
    vConsoleOrigScrBufferInfo.dwSize.Y=
        vConsoleOrigScrBufferInfo.srWindow.Bottom-
        vConsoleOrigScrBufferInfo.srWindow.Top + 1;
    vConsoleOrigScrBufferInfo.dwMaximumWindowSize=
        vConsoleOrigScrBufferInfo.dwSize;




    set_mode( 0, 0, 0 );



    /*
     *  Start reading the first file. Displaying can't start until
     *  the ini file (if one is found) is processed.
     */
    vReaderFlag = F_NEXT;

    /*
     *  Init priority setting for display & reader thread.
     *
     *      THREAD_PRIORITY_NORMAL       = reader thread normal pri.
     *      THREAD_PRIORITY_ABOVE_NORMAL = display thread pri
     *      THREAD_PRIORITY_HIGHEST      = reader thread in boosted pri.
     */
    vReadPriNormal = THREAD_PRIORITY_NORMAL;
    SetThreadPriority( GetCurrentThread(),
                       THREAD_PRIORITY_ABOVE_NORMAL );
    vReadPriBoost = THREAD_PRIORITY_NORMAL;


    /*
     *  Start reader thread
     */
    CreateThread( NULL,
                  STACKSIZE,
                  (LPTHREAD_START_ROUTINE) ReaderThread,
                  NULL, // lpParameter,
                  0, // THREAD_ALL_ACCESS,
                  &dwThreadId );


    /*
     *  Read INI information.
     */
    vSetWidth = vWidth;                     /* Set defaults             */
    vSetLines = vLines + 2;

    FindIni ();
    if (vSetBlks < vMaxBlks)
        vSetBlks  = DEFBLKS;

    vSetThres = (long) (vSetBlks/2-2) * BLOCKSIZE;

    /*
     *  Must wait for reader thread to at least read in the
     *  first block. Also, if the file was not found and only
     *  one file was specifed the reader thread will display
     *  an error and exit... if we don't wait we could have
     *  changed the screen before this was possible.
     */
    DosSemRequest (vSemMoreData, WAITFOREVER);


    /*
     *  Now that ini file has been read. Set parameters.
     *  Pause reader thread while adjusting buffer size.
     */
    SyncReader ();

    vMaxBlks    = vSetBlks;
    vThreshold  = vSetThres;
    vReaderFlag = F_CHECK;
    DosSemClear   (vSemReader);


    /*
     *  Now set to user's default video mode
     */

    set_mode (vSetLines, vSetWidth, 0);


    SetConsoleActiveScreenBuffer( vhConsoleOutput );

    //
    //      davegi/jaimes - 08/26/91
    //
    // Make List think it has one less line than the screen buffer.
    // This 'solves' the scrolling problem when Enter is pressed for a
    // command.
    // This is necessary because list uses the ReadFile() API to read
    // a string. ReadFile() echoes the carriage return and line feed
    // to the screen, and as the cursor is in the last line, the screen
    // is scolled one line up. By leaving one empty line after the
    // command line, this problem is eliminated.
    //

// T-HeathH 06/23/94
//
// Moved the hack to set_mode, where it will be used whenever that
// code thinks it has resized the display.
//
// That change subsumed this onld one.
//
//    vLines--;



}