Example #1
0
uintptr_t CPROC Thread2( PTHREAD thread )
{
   while( 1 )
	if( pc )
	{
      EnterCriticalSec( &cs );
		DestroyFrame( &pc );
      LeaveCriticalSec( &cs );

	}
	else
      Relinquish();
   return 0;
}
Example #2
0
uintptr_t CPROC Thread1( PTHREAD thread )
{
   while( 1 )
	if( !pc )
	{
      EnterCriticalSec( &cs );
		pc = CreateFrame( "test frame", 0, 0, 256, 256, 0, NULL );
      DisplayFrame( pc );
      LeaveCriticalSec( &cs );
	}
	else
      Relinquish();
   return 0;
}
Example #3
0
FILEMONITOR_PROC( void, EndMonitor )( PMONITOR monitor )
{
	if( !monitor )
		return;
	if( monitor->flags.bDispatched || monitor->flags.bScanning )
	{
		monitor->flags.bEnd = 1;
		return;
	}
	if( monitor->flags.bClosing )
	{
		if( l.flags.bLog ) Log( WIDE("Monitor already closing...") );
		return;
	}
	EnterCriticalSec( &monitor->cs );
	monitor->flags.bClosing = 1;
	monitor->flags.bRemoveFromEvents = 1;

	if( !monitor->flags.bRemovedFromEvents )
	{
		SetEvent( l.hMonitorThreadControlEvent );
		while( !monitor->flags.bRemovedFromEvents )
			Relinquish();
	}
	//Log1( WIDE("Closing the monitor on %s and killing thread...")
	//    , monitor->directory );
	if( monitor->hChange != INVALID_HANDLE_VALUE )
	{
		lprintf( WIDE( "close ntoification (wakes thread?" ) );
		FindCloseChangeNotification( monitor->hChange );
		lprintf( WIDE( "and then we wait..." ) );
	}
	monitor->hChange = INVALID_HANDLE_VALUE;
	{
		uint32_t tick = timeGetTime();
		while( monitor->pThread && ( ( tick+50 ) > timeGetTime() ) )
			Relinquish();
	}
	if( monitor->pThread )
	{
		EndThread( monitor->pThread );
	}
	//else
	//	Log( WIDE("Thread already left...") );
	CloseFileMonitors( monitor );
	RemoveTimer( monitor->timer );
	UnlinkThing( monitor );
	LeaveCriticalSec( &monitor->cs );
	Release( monitor );
}
Example #4
0
	inline void Lock( void ) { EnterCriticalSec( &cs ); }
Example #5
0
void Lock( PCONSOLE_INFO pmdp )
{
	EnterCriticalSec( &pmdp->Lock );
}
Example #6
0
VOID KeyEventProc(PCONSOLE_INFO pdp, KEY_EVENT_RECORD event)
{
#ifdef USE_OLD_CODE
   // this must here gather keystrokes and pass them forward into the
   // opened sentience...
//   PTEXT temp;
	int bOutput = FALSE;
   lprintf( "Entering handle a key event..." );
	Lock( pdp );
   lprintf( "Got the lock, waiting for collection buffer..." );
   if( event.bKeyDown )
   {
      PTEXT key;
      // here is where we evaluate the curent keystroke....

      for( ; event.wRepeatCount; event.wRepeatCount-- )
      {
         int mod = KEYMOD_NORMAL;
         extern PSIKEYDEFINE KeyDefs[];
         if(event.dwControlKeyState& (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
            mod |= KEYMOD_CTRL;
         if(event.dwControlKeyState& (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED))
            mod |= KEYMOD_ALT;
         if( KeyDefs[event.wVirtualKeyCode].flags & KDF_CAPSKEY )
         {
            if( event.dwControlKeyState & CAPSLOCK_ON )
            {
               if( !(event.dwControlKeyState& SHIFT_PRESSED) )
                  mod |= KEYMOD_SHIFT;
            }
            else
            {
               if( event.dwControlKeyState& SHIFT_PRESSED )
                  mod |= KEYMOD_SHIFT;
            }
         }
         else
            if( event.dwControlKeyState& SHIFT_PRESSED )
               mod |= KEYMOD_SHIFT;
         if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke ||
             pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
         {
            if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke )
            {
               bOutput |= DoStroke(pdp, pdp->Keyboard[event.wVirtualKeyCode][mod].data.stroke);
            }
            else if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
            {
               if( pdp->common.Owner->pRecord != pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro )
                  InvokeMacro( pdp->common.Owner
                             , pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro
                             , NULL );
               // do macro!!!!!
            }
         }
         else
         {
				if( key = KeyDefs[event.wVirtualKeyCode].op[mod].data.pStroke )
				{
					if( KeyDefs[event.wVirtualKeyCode].op[mod].bFunction )
						bOutput |= ((KeyFunc)key)(pdp);
					else
					{
						bOutput |= DoStroke( pdp, key );
					}
				}
         }
      }
      // call to clear and re-write the current buffer....
      //if( bOutput ) // so we don't output on shift, control, etc...
         //RenderCommandLine( pdp );
   }
   else
   {
      // key up's don't matter like ever...
   }
	Unlock( pdp );
#else
   // this must here gather keystrokes and pass them forward into the
   // opened sentience...
//   PTEXT temp;
   int bOutput = FALSE;
   int mod = KEYMOD_NORMAL;
   if( !pdp ) // not a valid window handle/device path
        return;
   //Log( "Entering keyproc..." );
   EnterCriticalSec( &pdp->Lock );
   //while( LockedExchange( &pdp->common.CommandInfo->CollectionBufferLock, 1 ) )
   //   Sleep(0);
   Log1( "mod = %x", pdp->dwControlKeyState );
   mod = pdp->dwControlKeyState;

   if( KeyDefs[event.wVirtualKeyCode].flags & KDF_CAPSKEY )
   {
      if( event.dwControlKeyState & CAPSLOCK_ON )
      {
         mod ^= KEYMOD_SHIFT;
      }
   }

   if( event.bKeyDown )
   {
      for( ; event.wRepeatCount; event.wRepeatCount-- )
		{
			unsigned char KeyState[256];
			DECLTEXT( key, "                   " );
			GetKeyboardState( KeyState );
			SetTextSize( &key, ToAscii( event.wVirtualKeyCode
											  , event.wVirtualScanCode
											  , KeyState
											  , (unsigned short*)key.data.data
											  , 0 ) );
			KeyPressHandler( pdp, event.wVirtualKeyCode, mod, (PTEXT)&key );
		}
#if 0
      // here is where we evaluate the curent keystroke....
      for( ; event.wRepeatCount; event.wRepeatCount-- )
		{

         // check current keyboard override...
         if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke ||
             pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
         {
            if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke )
            {
               bOutput |= DoStroke(pdp, pdp->Keyboard[event.wVirtualKeyCode][mod].data.stroke);
            }
            else if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
            {
               if( pdp->common.Owner->pRecord != pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro )
                  InvokeMacro( pdp->common.Owner
                             , pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro
                             , NULL );
            }
         }
         else // key was not overridden
         {
            int result;
            Log1( "Keyfunc = %d", KeyDefs[event.wVirtualKeyCode].op[mod].bFunction );
            switch( KeyDefs[event.wVirtualKeyCode].op[mod].bFunction )
            {
            case KEYDATA_DEFINED:
               Log( "Key data_defined" );
               bOutput |= DoStroke( pdp, (PTEXT)&KeyDefs[event.wVirtualKeyCode].op[mod].data.pStroke );
                    result = UPDATE_NOTHING; // unsure about this - recently added.
                    // well it would appear that the stroke results in whether to update
                    // the command prompt or not.
                break;
            case KEYDATA:
               {
                  char KeyState[256];
                  DECLTEXT( key, "                   " );
                  GetKeyboardState( KeyState );
                  SetTextSize( &key, ToAscii( event.wVirtualKeyCode
                                            , event.wVirtualScanCode
                                            , KeyState
                                            , (void*)key.data.data
                                            , 0 ) );
                  if( GetTextSize( (PTEXT)&key ) )
                     bOutput |= DoStroke( pdp, (PTEXT)&key );
                  result = UPDATE_NOTHING; // already taken care of?!
               }
               break;
            case COMMANDKEY:
               result = KeyDefs[event.wVirtualKeyCode].op[mod].data.CommandKey( pdp->common.CommandInfo );
               break;
            case HISTORYKEY:
               result = KeyDefs[event.wVirtualKeyCode].op[mod].data.HistoryKey( pdp->pHistoryDisplay );
               break;
            case CONTROLKEY:
               KeyDefs[event.wVirtualKeyCode].op[mod].data.ControlKey( &pdp->dwControlKeyState, TRUE );
               result = UPDATE_NOTHING;
               break;
            case SPECIALKEY:
               result = KeyDefs[event.wVirtualKeyCode].op[mod].data.SpecialKey( pdp );
               break;
            }
            switch( result )
            {
            case UPDATE_COMMAND:
               bOutput = TRUE;
               break;
				case UPDATE_HISTORY:
					if( UpdateHistory( pdp ) )
						DoRenderHistory(pdp, TRUE);
						DoRenderHistory(pdp, FALSE);

					break;
				case UPDATE_DISPLAY:
					ChildCalculate( pdp );
					break;
            }
         }
      }
      //if( bOutput )
		//   RenderCommandLine( pdp );
#endif
   }
   else
   {
    // flag is redundant for CONTOLKEY type...
      // key up's only matter if key is upaction flaged...
    switch( KeyDefs[event.wVirtualKeyCode].op[mod].bFunction )
    {
        case CONTROLKEY:
            KeyDefs[event.wVirtualKeyCode].op[mod].data.ControlKey( &pdp->dwControlKeyState, FALSE );
            break;
        }
   }
   LeaveCriticalSec( &pdp->Lock );
   //lprintf( "Left critical section on wincon." );
#endif
}
Example #7
0
RENDER_PROC( int, SetActiveGLDisplayView )( PVIDEO hDisplay, int nFracture )
{
	static CRITICALSECTION cs;
	static int first = 1;
	static PVIDEO _hDisplay; // last display with a lock.
	if( first )
	{
		InitializeCriticalSec( &cs );
		first = 0;
	}
	if( hDisplay )
	{
      HDC hdcEnable;
		//if( !IsVidThread() )
		//	return 0;
		EnterCriticalSec( &cs );
		EnterCriticalSec( &hDisplay->cs );
		if( nFracture )
		{
			nFracture -= 1;
			if( hDisplay->_prior_fracture != nFracture )
			{
				if(!wglMakeCurrent( (HDC)hDisplay->pFractures[nFracture].hDCBitmap
									, hDisplay->pFractures[nFracture].hRC))               // Try To Activate The Rendering Context
				{
					Log1( WIDE("GetLastERror == %d"), GetLastError() );
					//MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
					return FALSE;                       // Return FALSE
				}

				if( hDisplay->pFractures[nFracture].pImage->height==0 )         // Prevent A Divide By Zero By
				{
					hDisplay->pFractures[nFracture].pImage->height=1;            // Making Height Equal One
				}
				glViewport(0,0
					,hDisplay->pFractures[nFracture].pImage->real_width
					,hDisplay->pFractures[nFracture].pImage->real_height);                // Reset The Current Viewport
				hDisplay->_prior_fracture = nFracture;
				//lprintf( WIDE("lock+1") );
				_hDisplay = hDisplay;
            //if( hDisplay->_prior_fracture == -1 )
				//	EnterCriticalSec( &cs );
			}
			else
			{
				lprintf( WIDE( "Last fracture is the same as current." ) );
			}
		}
		else
		{
			if( hDisplay->flags.bLayeredWindow )
            hdcEnable = hDisplay->ENABLE_ON_DC_LAYERED;
			else
            hdcEnable = hDisplay->ENABLE_ON_DC_NORMAL;
			if( _hDisplay )
			{
				LeaveCriticalSec( &_hDisplay->cs );
				//LeaveCriticalSec( &cs ); // leave once?!
            _hDisplay = NULL;
			}
			if( !_hDisplay )
			{
				if(!wglMakeCurrent(hdcEnable,hDisplay->hRC))               // Try To Activate The Rendering Context
				{
					DebugBreak();

					Log1( WIDE("GetLastERror == %d"), GetLastError() );
					//MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
					return FALSE;                       // Return FALSE
				}

				if( hDisplay->pImage->height==0 )         // Prevent A Divide By Zero By
				{
					hDisplay->pImage->height=1;            // Making Height Equal One
				}
				glViewport(0,0,hDisplay->pImage->real_width,hDisplay->pImage->real_height);                // Reset The Current Viewport
				//lprintf( "lock+1");
				//EnterCriticalSec( &cs );
				_hDisplay = hDisplay;
			}
			else
			{
				if( hDisplay == _hDisplay )
				{
					lprintf( WIDE("Active GL Context already on this renderer...") );
				}
				else
				{
					DebugBreak();
					lprintf( WIDE("Active GL context is on another Display... please wait?!") );
				}
			}
		}
	}
	else
	{
		//__try {
		//glFlush();
		//}
		//__except ( EXCEPTION_EXECUTE_HANDLER ) {
		//	lprintf( "gl stack f****d.  Wonder where we can recover." );
		//}
		if( _hDisplay )
		{
#ifdef LOG_OPENGL_CONTEXT
			lprintf( WIDE( "Prior GL Context being released." ) );
#endif
			lprintf( WIDE( "swapping buffer..." ) );
			glFlush();
			if( _hDisplay->flags.bLayeredWindow )
			{
				SwapBuffers( _hDisplay->hDCFakeWindow );
				//ReadBuffer( _hDisplay->PBO );
			}
         else
				SwapBuffers( _hDisplay->hDCOutput );

			lprintf( WIDE( "Steal surface from fake into my bitmap..." ) );


         lprintf( WIDE( "Read from buffer is how Slow?" ) );
			//BitBlt ((HDC)_hDisplay->hDCFakeBitmap, 0, 0, _hDisplay->pWindowPos.cx, _hDisplay->pWindowPos.cy,
			//		  (HDC)_hDisplay->hDCFakeWindow, 0, 0, SRCCOPY);
			if(!wglMakeCurrent( NULL, NULL) )               // Try To Deactivate The Rendering Context
			{
				DebugBreak();
				Log1( WIDE("GetLastERror == %d"), GetLastError() );
				//MessageBox(NULL,"Can't Deactivate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
				return FALSE;                       // Return FALSE
			}
         lprintf(WIDE( " Failure %d" ), GetLastError() );
         lprintf( WIDE( "Done with that... shared surface, right? now we can put it out?" ) );

			_hDisplay->_prior_fracture = -1;
			//lprintf( "lock-1" );
			LeaveCriticalSec( &_hDisplay->cs );
			_hDisplay = NULL;
			//LeaveCriticalSec( &cs );
		}
		LeaveCriticalSec( &cs );
	}
	return TRUE;
}
Example #8
0
static PSERVICE_ROUTE _LoadService( CTEXTSTR service
							  , EventHandlerFunction EventHandler
							  , EventHandlerFunctionEx EventHandlerEx
							  , EventHandlerFunctionExx EventHandlerExx
							  , server_message_handler handler
                       , server_message_handler_ex handler_ex
							  , uintptr_t psv
							  )
{
	MSGIDTYPE MsgID;
	MsgSrv_ReplyServiceLoad msg;
	size_t MsgLen = sizeof( msg ); // expect MsgBase = 0, EventMessgaeCount = 1
	PEVENTHANDLER pHandler;

	// can check now if some other part of this has loaded
	// this service.
	// reset this status...

	if( !_InitMessageService( service?FALSE:TRUE ) )
	{
#ifdef DEBUG_MSGQ_OPEN
		lprintf( WIDE("Load of %s message service failed."), service );
#endif
		return NULL;
	}
	if( service )
	{
		RegisterWithMasterService();
		if( !g.flags.bAliveThreadStarted )
		{
			// this timer monitors ALL clients for inactivity
			// it will probe them with RU_ALIVE messages
			// to which they must respond otherwise be termintated.
			g.flags.bAliveThreadStarted = 1;
			AddTimer( CLIENT_TIMEOUT/4, MonitorClientActive, 0 );
			// each service gets 1 thread to handle their own
			// messages... services do not have 'events' generated
			// to them.
		}
#if 0
		// always query for service, don't short cut... ?
		while( pHandler )
		{
			// only one connection to any given service name
			// may be maintained.  The service itself is resulted...
			if( !strcmp( pHandler->servicename, service ) )
				return &pHandler->RouteID;
			pHandler = pHandler->next;
		}
#endif
		EnterCriticalSec( &g.csLoading );
		pHandler = New( EVENTHANDLER );
		MemSet( pHandler, 0, sizeof( EVENTHANDLER ) );
		//InitializeCriticalSec( &pHandler->csMsgTransact );
		pHandler->servicename = StrDup( service );

		pHandler->RouteID.dest.process_id = 1;
		pHandler->RouteID.dest.service_id = 0;
		pHandler->RouteID.source.process_id = g.my_message_id;
		pHandler->RouteID.source.service_id = 0;

		//lprintf( WIDE("Allocating local structure which manages our connection to this service...") );
 
		// MsgInfo is used both on the send and receives the
		// responce from the service...
		// LoadService goes to the msgsvr and requests the
		// location of the service.
		if( !TransactRoutedServerMultiMessageEx( &pHandler->RouteID
															, MSG_ServiceLoad, 1
															, &MsgID, &msg, &MsgLen
															, 250 /* short timeout */
															, service, (StrLen( service ) + 1) *sizeof(TEXTCHAR) // include NUL
															) )
		{
			Log( WIDE("Transact message timeout.") );
			Release( pHandler );
			LeaveCriticalSec( &g.csLoading );
			return NULL;
		}
		if( MsgID != (MSG_ServiceLoad|SERVER_SUCCESS) )
		{
			lprintf( WIDE("Server reports it failed to load [%s] (%08") _MsgID_f WIDE("!=%08" ) _MsgID_f WIDE(")")
					 , service
					 , MsgID
					 , (MSGIDTYPE)(MSG_ServiceLoad|SERVER_SUCCESS) );
			Release( pHandler );
			LeaveCriticalSec( &g.csLoading );
			return NULL;
		}
		// uncorrectable anymore.
		//if( MsgLen == 16 )
		//{
		//	lprintf( WIDE("Old server load service responce... lacks the PID of the event handler.") );
		//}
		if( MsgLen != sizeof( msg ) )
		{
			lprintf( WIDE("Server responce was the wrong length!!! %") _size_f WIDE(" expecting %")_size_f, MsgLen, sizeof( msg ) );
			Release( pHandler );
			LeaveCriticalSec( &g.csLoading );
			return NULL;
		}
	}
	else
	{
		// loading special NULL service.
		// the NULL service looks like a queue available
      // for events only?  fakes a server response in msg.
		pHandler = New( EVENTHANDLER );
		MemSet( pHandler, 0, sizeof( EVENTHANDLER ) );
		//InitializeCriticalSec( &pHandler->csMsgTransact );
		pHandler->RouteID.dest.process_id = g.my_message_id;
		pHandler->RouteID.dest.service_id = 0;
		pHandler->servicename = StrDup( WIDE("local_events") );

		msg.ServiceID = 0; // this is a special event channel to myself.

		//lprintf( WIDE("opening local only service... we're making up numbers here.") );
		if( g.pLocalEventThread )
		{
			msg.thread = GetThreadID( g.pLocalEventThread );
		}
		else
		{
			lprintf( WIDE("Event message system has not started correctly...") );
			Release( pHandler );
			LeaveCriticalSec( &g.csLoading );
			return NULL;
		}
	}

	// EVENTHANDLER is the outbound structure to idenfity
	// the service information which messages go where...
	{
		//pHandler = Allocate( sizeof( EVENTHANDLER ) + strlen( service?service:"local_events" ) );
		//strcpy( pHandler->servicename, service?service:"local_events" );
		//lprintf( WIDE("Allocating local structure which manages our connection to this service...") );
		pHandler->flags.destroyed = 0;
		pHandler->flags.dispatched = 0;

		//pHandler->MsgCountEvents = msg.events;
		//pHandler->MsgCount = msg.functions;
		pHandler->Handler = EventHandler;
		pHandler->HandlerEx = EventHandlerEx;
		pHandler->HandlerExx = EventHandlerExx;
      pHandler->psv = psv;
		// thread ID to wake for events? or to probe?
		// thread ID unused.
		pHandler->EventID = msg.thread;
		if( service )
		{
			pHandler->flags.local_service = 0;
			//pHandler->RouteID.dest = msg.ServiceID; // magic place where source ID is..
			pHandler->msgq_events = g.msgq_event;
		}
		else
		{
			pHandler->flags.local_service = 1;
			pHandler->RouteID.dest.process_id = g.my_message_id;
			pHandler->RouteID.dest.service_id = 0;
			pHandler->msgq_events = g.msgq_local;
		}
		LinkThing( g.pHandlers, pHandler );
		if( service )
		{
			PSERVICE_CLIENT pClient = AddClient( &pHandler->RouteID ); // hang this on the list of services to check...
			pClient->flags.is_service = 1;
			pClient->handler = pHandler;
		}
		LeaveCriticalSec( &g.csLoading );
	}
	return &pHandler->RouteID;
}