Gnats XXXX -- Solaris GUI Ghosting / Non-thread safe event processing
Phil Weinstein -- June 6, 2007 -- IMAGES:

Workspace Open Slot Stack Trace Debugger
InteractiveMode
Debugger
rwGuiExecute
Source
customEventProcess
//=======================================================
//+public
//
// METHOD: 
// void QtIntegration::customEventProcess()
//
// PURPOSE: 
// Provides the integrated event loop strategy for the current platform.
// This method should be called in place of veventProcess().
//
// PARAMETERS:
// none
//
// RETURN VALUES:
// none
//
void QtIntegration::customEventProcess()
{
  // Load the environment variable for the usleep() duration in microseconds
  static int sleepMilliseconds = -1;
  static int sleepMicroseconds = -1;
  if (sleepMicroseconds == -1)
  {
     RWCString sleepMicrosecondsString;
     if (cwGetEnv("RW_GUI_SLEEP", sleepMicrosecondsString))
     {
        sleepMicroseconds = (int)atof(sleepMicrosecondsString);
     }
     else
     {
        // Default sleep time is 1 millisecond (1000 microseconds)
        sleepMicroseconds = 1000;
     }
     sleepMilliseconds = sleepMicroseconds / 1000;
  }

  while (1)
  {
     // Post a marker event which stops the loop when reached.
     // This allows the loop only to process events currently
     // in the queue.  Once these events have been handled, the
     // event loop will stop.
     vevent *clientEvent = veventCreateClient();
     veventSetTarget(clientEvent, galaxyMarkerEventHandler);
     veventSetPriority(clientEvent, veventPRIORITY_MIN);
     veventPost(clientEvent);

     // Run the short galaxy event loop.
     //
     // MSVC: for compiling on PCs without a Galaxy license.
#  if defined(CW_MSVC) && defined(CW_VEVENT)
     eventProcess();
#  else
     veventProcess();
#  endif

     // Call the preBlockHandler, since the event loop won't be doing this
     (veventGetPreBlockHandlerProc())();

     // Handle Qt events
     //
     // The argument to processEvents() specifies how long to continue
     // processing queued events.  If no events are on the queue this method 
     // will stop processing and return.
     qApp->processEvents(10);

     // Some deletions may occur in the future, so once the quit flag 
     // has been set do several more iterations of event handling.
     if (_galaxyQuit) {
        if (_numFinalLoops++ >= MAX_FINAL_LOOPS) {
           break;
        }
     }

     // Take a load off the CPU for a few microseconds
     //
#if defined(CW_MSVC)
     Sleep(sleepMilliseconds);
#else
     usleep(sleepMicroseconds);
#endif
  }

  // Force Qt to exit and close all windows
  qApp->exit();
}