void DThread_TestCancel( DThread *self ) { if( self->thdSpecData->state & DTHREAD_CANCELED ){ self->thdSpecData->state = 0; DThread_Exit( self ); } }
void DThread_Wrapper( void *object ) { DThread *self = (DThread*)object; self->running = 1; if( self->thdSpecData == NULL ){ self->thdSpecData = (DThreadData*)GlobalAlloc( GPTR, sizeof(DThreadData) ); self->thdSpecData->thdObject = self; } self->thdSpecData->state = 0; TlsSetValue( thdSpecKey, self->thdSpecData ); if( self->taskFunc ) self->taskFunc( self->taskArg ); DThread_Exit( self ); }
void DCondVar_Wait( DCondVar *self, DMutex *mtx ) { DThreadData *p = (DThreadData*)TlsGetValue( thdSpecKey ); DMutex_Lock( & self->thdMutex ); DArray_PushBack( self->thdWaiting, (void*) p->thdObject ); DMutex_Unlock( & self->thdMutex ); if( mtx ) DMutex_Unlock( mtx ); WaitForSingleObject( p->thdObject->condv.myCondVar, INFINITE ); ResetEvent( p->thdObject->condv.myCondVar ); if( mtx ) DMutex_Lock( mtx ); if( p->state & DTHREAD_CANCELED ) DThread_Exit( p->thdObject ); }
int DCondVar_TimedWait( DCondVar *self, DMutex *mtx, double seconds ) { DWORD retc; DThreadData *p = (DThreadData*)TlsGetValue( thdSpecKey ); DMutex_Lock( & self->thdMutex ); DArray_PushBack( self->thdWaiting, (void*) p->thdObject ); DMutex_Unlock( & self->thdMutex ); if( mtx ) DMutex_Unlock( mtx ); retc = WaitForSingleObject( p->thdObject->condv.myCondVar, (DWORD)( seconds * 1000 ) ); ResetEvent( p->thdObject->condv.myCondVar ); if( mtx ) DMutex_Lock( mtx ); if( p->state & DTHREAD_CANCELED ) DThread_Exit( p->thdObject ); return ( retc == WAIT_TIMEOUT ); }
void DThread_Wrapper( void *object ) { DThread *self = (DThread*)object; self->running = 1; if( self->thdSpecData == NULL ){ self->thdSpecData = DThreadData_New(); self->thdSpecData->thdObject = self; } self->state = 0; self->vmpause = 0; self->vmpaused = 0; self->vmstop = 0; self->vmstopped = 0; if( self->taskFunc ) self->taskFunc( self->taskArg ); DThread_Exit( self ); }