Exemplo n.º 1
0
VOID InitDebugThread( VOID )
{
    TID                 tid;

    DosSemSet( &StopDoneSem );
    DosSemSet( &DebugReqSem );
    DosCreateThread( DoDebugRequests, &tid, stack + STACK_SIZE );
    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, tid );
}
Exemplo n.º 2
0
void InitScreen( void )
{
    TID                 tid;

    RestoreMainScreen( "WDPM" );
    DosSemSet( &PumpMessageSem );
    DosSemSet( &PumpMessageDoneSem );
    DosCreateThread( (PFNTHREAD)PumpMessageQueue, &tid, Stack+STACK_SIZE );
    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, tid );
}
Exemplo n.º 3
0
static bool InitServer( void )
{
    TID tid;

    DosSemSet( &BroadCastStop );
    DosSemSet( &BroadCastStart );
    DosCreateThread( Broadcast, &tid, BroadcastStack + STACKSIZE );
    DosSemWait( &BroadCastStart, -1L );
    DosCreateThread( Respond, &tid, RespondStack + STACKSIZE );
    return( TRUE );
}
Exemplo n.º 4
0
static trap_retval DoRemotePut( byte *snd, trap_elen len )
{
    WORD        rc;

putstring( "RemotePut\r\n" );
putconnstatus( Connection );
    if( len == 0 ) {
        _INITSPXECB( Send, 1, NULL, 0 );
    } else {
        _INITSPXECB( Send, 2, (char *)snd, len );
    }
    SendECB.hsem = (HSEM) &SendSem;
    SendHead.connectionCtl |= 0x10;
    SendHead.packetLen = _SWAPINT( sizeof( SendHead ) + len );
    DosSemSet( &SendSem );
    rc = SpxSendSequencedPacket( Connection, &SendECB );
    putrc( "SPXSendSequencedPacket", rc );

    for( ;; ) {
        /*
            I don't know what the 0x1001 status is - I can't find it
            in any documentation, but if we don't wait for it to clear,
            things mess up badly.
        */
        if( SendECB.status != SPX_SUCCESSFUL && !InUse( SendECB ) && SendECB.status != 0x1001 )
            break;
        rc = DosSemWait( &SendSem, 1000 );
        if( rc != ERROR_SEM_TIMEOUT ) {
            break;
        }
    }
    SendECB.hsem = 0;
putstring( "Done RemotePut\r\n" );
    return( len );
}
Exemplo n.º 5
0
unsigned OnAnotherThreadSimpAccess( unsigned in_len, in_data_p in_data, unsigned out_len, out_data_p out_data )
{
    unsigned    result;

    if( !ToldWinHandle || IsTrapFilePumpingMessageQueue() ) {
        return( TrapSimpAccess( in_len, in_data, out_len, out_data ) );
    } else {
        DosSemClear( &PumpMessageSem );
        result = TrapSimpAccess( in_len, in_data, out_len, out_data );
        WinPostMsg( GUIGetSysHandle( WndGui( WndMain ) ), WM_QUIT, 0, 0 );
        DosSemWait( &PumpMessageDoneSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageDoneSem );
        return( result );
    }
}
Exemplo n.º 6
0
unsigned OnAnotherThreadAccess( trap_elen in_num, in_mx_entry_p in_mx, trap_elen out_num, mx_entry_p out_mx )
{
    unsigned    result;

    if( !ToldWinHandle || IsTrapFilePumpingMessageQueue() ) {
        return( TrapAccess( in_num, in_mx, out_num, out_mx ) );
    } else {
        DosSemClear( &PumpMessageSem );
        result = TrapAccess( in_num, in_mx, out_num, out_mx );
        WinPostMsg( GUIGetSysHandle( WndGui( WndMain ) ), WM_QUIT, 0, 0 );
        DosSemWait( &PumpMessageDoneSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageDoneSem );
        return( result );
    }
}
Exemplo n.º 7
0
unsigned OnAnotherThread( unsigned(*rtn)(unsigned,void *,unsigned,void *), unsigned in_len, void *in, unsigned out_len, void *out )
{
    unsigned    result;

    if( !ToldWinHandle || IsTrapFilePumpingMessageQueue() ) {
        return( rtn( in_len, in, out_len, out ) );
    } else {
        DosSemClear( &PumpMessageSem );
        result = rtn( in_len, in, out_len, out );
        WinPostMsg( GUIGetSysHandle( WndGui( WndMain ) ), WM_QUIT, 0, 0 );
        DosSemWait( &PumpMessageDoneSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageDoneSem );
        return( result );
    }
}
Exemplo n.º 8
0
static VOID APIRET DoDebugRequests( VOID )
{
    for( ;; ) {
        DosSemWait( &DebugReqSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &DebugReqSem );
        InDosDebug = TRUE;
        DebugReqResult = Call32BitDosDebug( DebugReqBuff );
        InDosDebug = FALSE;
        if( IsPMDebugger() ) {
            WinPostMsg( HwndDebugger, WM_QUIT, 0, 0 );
        } else {
            DosSemClear( &DebugDoneSem );
        }
    }
}
Exemplo n.º 9
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);
    }
}
Exemplo n.º 10
0
static trap_retval DoRemoteGet( byte *rec, trap_elen len )
{
    int         i;
    int         p;
    unsigned    recvd;
    unsigned    got;

putstring( "RemoteGet\r\n" );
putconnstatus( Connection );

    len = len;
    recvd = 0;
    for( ;; ) {
        DosSemSet( &RecvSem );
        i = NUM_REC_BUFFS-1;
        p = -1;
        for( ;; ) {
            if( i < 0 ) {
                if( p != -1 ) break;
                DosSemWait( &RecvSem, 1000 );
                i = NUM_REC_BUFFS-1;
            }
            if( !InUse( RecECB[i] ) ) {
                if( p == -1
                 || LOWER_SEQ( RecHead[i].sequenceNumber, RecHead[p].sequenceNumber ) ) {
                    p = i;
                }
            }
            --i;
        }
        got = _SWAPINT( RecHead[p].packetLen ) - sizeof( RecHead[p] );
        _fmemcpy( rec, Buffer[p], got );
        recvd += got;
        PostAListen( p );
        if( got != MAX_DATA_SIZE ) break;
        rec += got;
    }

putstring( "Done RemoteGet\r\n" );
    return( recvd );
}
Exemplo n.º 11
0
VOID PumpMessageQueue( VOID )
{
    char        class_name[80];
    QMSG        qmsg;
    ERRORID     err;

    for( ;; ) {
        DosSemWait( &PumpMessageSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageSem );
        WinThreadAssocQueue( GUIGetHAB(), GUIPMmq );
        while( WinGetMsg( GUIGetHAB(), &qmsg, 0L, 0, 0 ) ) {
            WinQueryClassName( qmsg.hwnd, sizeof( class_name ), class_name );
            if( strcmp( class_name, "GUIClass" ) == 0 ||
                strcmp( class_name, "WTool" ) == 0 ) {
                WinDefWindowProc( qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2 );
            } else {
                WinDispatchMsg( GUIGetHAB(), &qmsg );
            }
        }
        WinThreadAssocQueue( GUIGetHAB(), NULL );
        err = WinGetLastError( GUIGetHAB() );
        DosSemClear( &PumpMessageDoneSem );
    }
}
Exemplo n.º 12
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);

}  
Exemplo n.º 13
0
VOID FAR PMfrThread (VOID)
     {
     int sub_rc;

     habThread = WinInitialize(0);

     WinGetLastError(habThread);

   /* get the memory DC */
   cp.hdcMemory = DevOpenDC (habThread, OD_MEMORY, "*", 0L, NULL, NULL) ;
   /* this says that we don't have a PS yet; not one to destroy */
   cp.hpsMemory = (HPS) NULL;

     /* let each sub-driver have a crack at it now */
     PrintDriverInit();
     CalcDriverInit();

     /* Initialization here is done.
        Post main thread that we are going to work
     */

     WinPostMsg(cp.hwnd, WM_THRD_POST,
                MPFROM2SHORT(SUB_INIT_DONE, 0),
                MPFROMP(NULL) );

     for (;;)
          {  /* wait for something to do */
          DosSemWait (&cp.ulSemTrigger, SEM_INDEFINITE_WAIT) ;

          /* take an early exit for Shutdown */
          if (cp.sSubAction == SUB_ACT_TERM)
             break;

          /* posted out of wait.  do something */

          switch(cp.sSubAction)
                {
                case SUB_ACT_CALC:
                     sub_rc = CalcDriver();
                     break;
                case SUB_ACT_PRINT:
                     sub_rc = PrintDriver();
                     break;
                case SUB_ACT_SAVE:
                     sub_rc = SaveDriver();
                     break;
                case SUB_ACT_LOAD:
                     sub_rc = LoadDriver();
                     break;
                default:
                     sub_rc = 0x9999;   /* let the main task figure it out */
                     break;
                }

          /* test here for shutdown also */
          if (cp.sSubAction == SUB_ACT_TERM)
              break;

          /* not shutdown. */
          /* indicate ready for the next cycle */
          DosSemSet (&cp.ulSemTrigger) ;
          WinPostMsg (cp.hwnd, WM_THRD_POST, MPFROM2SHORT(sub_rc, 0) ,
                         MPFROMP(NULL) ) ;
          }

      /* shutdown has been triggered.
         release resources obtained by us.

         NOTE: Serialize using DosEnterCritSec so that
         the main thread is dormant until we get everything
         cleaned up and go away.  The main thread will be
         re-dispatched following our final DosExit.
      */

      DosEnterCritSec();

      if (cp.hpsMemory != (HPS) 0)
         {  /* protection from a failed WM_CREATE or IDM_GO */
         GpiSetBitmap(cp.hpsMemory, (HBITMAP) NULL);
         GpiDestroyPS(cp.hpsMemory);
         GpiDeleteBitmap (cp.hbmMemory);
         }
      cp.hpsMemory = (HPS) 0;

      if ( cp.pixels != NULL)
         hfree(cp.pixels);
      cp.pixels = NULL;

      if (cp.hdcMemory != (HDC) 0)
         DevCloseDC (cp.hdcMemory);
      cp.hdcMemory = (HDC) 0;

      /* say good-bye to PM */
      WinTerminate(habThread);

      /* flag we done */
      DosSemClear ((HSEM) &cp.ulSemSubEnded);
      /* and go away */
      DosExit(EXIT_THREAD, 0);

      }
Exemplo n.º 14
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--;



}
Exemplo n.º 15
0
unsigned int CallDosDebug( dos_debug __far *buff )
{
    QMSG        qmsg;
    int         num_paints;
    int         i;
    struct {
        RECTL   rcl;
        HWND    hwnd;
    }           paints[MAX_PAINTS];
    HPS         ps;
    char        class_name[80];
    TID         tid;

    if( !IsPMDebugger() ) {
        return( Call32BitDosDebug( buff ) );
    }

    switch( buff->Cmd ) {
    case DBG_C_ClearWatch:
    case DBG_C_Freeze:
    case DBG_C_LinToSel:
    case DBG_C_NumToAddr:
    case DBG_C_ReadCoRegs:
    case DBG_C_ReadMemBuf:
    case DBG_C_ReadMem_D:
    case DBG_C_ReadReg:
    case DBG_C_SelToLin:
    case DBG_C_SetWatch:
    case DBG_C_ThrdStat:
    case DBG_C_WriteCoRegs:
    case DBG_C_WriteMemBuf:
    case DBG_C_WriteMem_D:
    case DBG_C_WriteReg:
        return( Call32BitDosDebug( buff ) );
    }
    switch( buff->Cmd ) {
    case DBG_C_Go:
    case DBG_C_SStep:
    case DBG_C_Term:
        ReleaseQueue( buff->Pid, buff->Tid );
    }
    DebugReqBuff = buff;
    StopBuff = *buff;
    DosSemSet( &DebugDoneSem );
    DosSemClear( &DebugReqSem );
    num_paints = 0;
    if( IsPMDebugger() ) {
        while( WinGetMsg( HabDebugger, &qmsg, 0L, 0, 0 ) || InDosDebug ) {
            WinQueryClassName( qmsg.hwnd, MAX_CLASS_NAME, class_name );
            switch( qmsg.msg ) {
            case WM_CHAR:
                if( ( SHORT1FROMMP( qmsg.mp1 ) & KC_VIRTUALKEY ) &&
                    ( SHORT2FROMMP( qmsg.mp2 ) == VK_BREAK ) ) {
                    SetBrkPending();
                    DosCreateThread( StopApplication, &tid, stack2 + STACK_SIZE );
                    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 10, tid );
                    WakeThreads( StopBuff.Pid );
                    DosSemWait( &StopDoneSem, SEM_INDEFINITE_WAIT );
                    DosSemSet( &StopDoneSem );
                }
                break;
            case WM_COMMAND:
                CantDoIt();
                break;
            default:
                if( strcmp( class_name, "GUIClass" ) == 0 ||
                    strcmp( class_name, "WTool" ) == 0 ) {
                    switch( qmsg.msg ) {
                    case WM_PAINT:
                        if( num_paints >= MAX_PAINTS ) --num_paints;
                        paints[num_paints].hwnd = qmsg.hwnd;
                        ps = WinBeginPaint( qmsg.hwnd, 0, &paints[ num_paints ].rcl );
                        GpiErase( ps );
                        WinEndPaint( ps );
                        num_paints++;
                        break;
                    case WM_BUTTON1DOWN:
                    case WM_BUTTON2DOWN:
                    case WM_BUTTON3DOWN:
                        CantDoIt();
                        break;
                    case WM_MOUSEMOVE:
                    {
                        HPOINTER hourglass = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE );
                        if( WinQueryPointer( HWND_DESKTOP ) != hourglass ) {
                            WinSetPointer( HWND_DESKTOP, hourglass );
                        }
                        break;
                    }
                    default:
                        WinDefWindowProc( qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2 );
                    }
                } else {
                    WinDispatchMsg( HabDebugger, &qmsg );
                }
            }
        }
    } else {
        DosSemWait( &DebugDoneSem, SEM_INDEFINITE_WAIT );
    }
    switch( buff->Cmd ) {
    case DBG_N_Exception:
    case DBG_N_AsyncStop:
    case DBG_N_Watchpoint:
        AssumeQueue( buff->Pid, buff->Tid );
        break;
    }
    for( i = 0; i < num_paints; ++i ) {
        WinInvalidateRect( paints[i].hwnd, &paints[i].rcl, FALSE );
    }
    return( DebugReqResult );
}
Exemplo n.º 16
0
static void NCBWaitInit(PNCB Ncb, BOOL wait)
{
  if (!wait)
    DosSemSet((HSEM) &Ncb -> basic_ncb.ncb_semaphore);
}