mod/maxgui.mod/fltkmaxgui.mod/src/Fl_mac.cxx
void* DataReady::DataReadyThread(void *o)
{
  DataReady *self = (DataReady*)o;
  while ( 1 )					// loop until thread cancel or error
  {
    // Thread safe local copies of data before each select()
    self->DataLock();
    /*LOCK*/  int maxfd = self->_maxfd;
    /*LOCK*/  fd_set r = self->GetFdset(0);
    /*LOCK*/  fd_set w = self->GetFdset(1);
    /*LOCK*/  fd_set x = self->GetFdset(2);
    /*LOCK*/  void *userdata = self->_userdata;
    /*LOCK*/  int cancelpipe = self->GetCancelPipe(0);
    /*LOCK*/  if ( cancelpipe > maxfd ) maxfd = cancelpipe;
    /*LOCK*/  FD_SET(cancelpipe, &r);		// add cancelpipe to fd's to watch
    /*LOCK*/  FD_SET(cancelpipe, &x);
    self->DataUnlock();
    // timeval t = { 1000, 0 };	// 1000 seconds;
    timeval t = { 2, 0 };	// HACK: 2 secs prevents 'hanging' problem
    int ret = ::select(maxfd+1, &r, &w, &x, &t);
    pthread_testcancel();	// OSX 10.0.4 and older: needed for parent to cancel
    switch ( ret )
    {
      case 0:	// NO DATA
        continue;
      case -1:	// ERROR
      {
        DEBUGPERRORMSG("CHILD THREAD: select() failed");
        return(NULL);		// error? exit thread
      }
      default:	// DATA READY
      {
	if (FD_ISSET(cancelpipe, &r) || FD_ISSET(cancelpipe, &x)) 	// cancel?
	    { return(NULL); }						// just exit
        DEBUGMSG("CHILD THREAD: DATA IS READY\n");
        EventRef drEvent;
        CreateEvent( 0, kEventClassFLTK, kEventFLTKDataReady,
		     0, kEventAttributeUserEvent, &drEvent);
        EventQueueRef eventqueue = (EventQueueRef)userdata;
        PostEventToQueue(eventqueue, drEvent, kEventPriorityStandard );
        ReleaseEvent( drEvent );
        return(NULL);		// done with thread
      }
    }
  }
}
// DATA READY THREAD
//    This thread watches for changes in user's file descriptors.
//    Sends a 'data ready event' to the main thread if any change.
//
DATA READY THREAD
This thread watches for changes in user's file descriptors.
Sends a 'data ready event' to the main thread if any change.
DATA READY THREAD This thread watches for changes in user ' s file descriptors . Sends a ' data ready event ' to the main thread if any change .
void* DataReady::DataReadyThread(void *o)
{
  DataReady *self = (DataReady*)o;
  while ( 1 )					
  {
    self->DataLock();
      int maxfd = self->_maxfd;
      fd_set r = self->GetFdset(0);
      fd_set w = self->GetFdset(1);
      fd_set x = self->GetFdset(2);
      void *userdata = self->_userdata;
      int cancelpipe = self->GetCancelPipe(0);
      if ( cancelpipe > maxfd ) maxfd = cancelpipe;
      FD_SET(cancelpipe, &r);		
      FD_SET(cancelpipe, &x);
    self->DataUnlock();
    timeval t = { 2, 0 };	
    int ret = ::select(maxfd+1, &r, &w, &x, &t);
    pthread_testcancel();	
    switch ( ret )
    {
      case 0:	
        continue;
      case -1:	
      {
        DEBUGPERRORMSG("CHILD THREAD: select() failed");
        return(NULL);		
      }
      default:	
      {
	if (FD_ISSET(cancelpipe, &r) || FD_ISSET(cancelpipe, &x)) 	
	    { return(NULL); }						
        DEBUGMSG("CHILD THREAD: DATA IS READY\n");
        EventRef drEvent;
        CreateEvent( 0, kEventClassFLTK, kEventFLTKDataReady,
		     0, kEventAttributeUserEvent, &drEvent);
        EventQueueRef eventqueue = (EventQueueRef)userdata;
        PostEventToQueue(eventqueue, drEvent, kEventPriorityStandard );
        ReleaseEvent( drEvent );
        return(NULL);		
      }
    }
  }
}
void * DataReady :: DataReadyThread ( void * o ) { DataReady * self = ( DataReady * ) o ; while ( 1 ) { self -> DataLock ( ) ; int maxfd = self -> _maxfd ; fd_set r = self -> GetFdset ( 0 ) ; fd_set w = self -> GetFdset ( 1 ) ; fd_set x = self -> GetFdset ( 2 ) ; void * userdata = self -> _userdata ; int cancelpipe = self -> GetCancelPipe ( 0 ) ; if ( cancelpipe > maxfd ) maxfd = cancelpipe ; FD_SET ( cancelpipe , & r ) ; FD_SET ( cancelpipe , & x ) ; self -> DataUnlock ( ) ; timeval t = { 2 , 0 } ; int ret = :: select ( maxfd + 1 , & r , & w , & x , & t ) ; pthread_testcancel ( ) ; switch ( ret ) { case 0 : continue ; case -1 : { DEBUGPERRORMSG ( " " ) ; return ( NULL ) ; } default : { if ( FD_ISSET ( cancelpipe , & r ) || FD_ISSET ( cancelpipe , & x ) ) { return ( NULL ) ; } DEBUGMSG ( " \n " ) ; EventRef drEvent ; CreateEvent ( 0 , kEventClassFLTK , kEventFLTKDataReady , 0 , kEventAttributeUserEvent , & drEvent ) ; EventQueueRef eventqueue = ( EventQueueRef ) userdata ; PostEventToQueue ( eventqueue , drEvent , kEventPriorityStandard ) ; ReleaseEvent ( drEvent ) ; return ( NULL ) ; } } } }
DATA READY THREAD
This thread watches for changes in user's file descriptors.
DATA READY THREAD This thread watches for changes in user ' s file descriptors .
// loop until thread cancel or error // Thread safe local copies of data before each select() /*LOCK*/ /*LOCK*/ /*LOCK*/ /*LOCK*/ /*LOCK*/ /*LOCK*/ /*LOCK*/ /*LOCK*/ // add cancelpipe to fd's to watch /*LOCK*/ // timeval t = { 1000, 0 };	// 1000 seconds; // HACK: 2 secs prevents 'hanging' problem // OSX 10.0.4 and older: needed for parent to cancel // NO DATA // ERROR // error? exit thread // DATA READY // cancel? // just exit // done with thread