void omni_thread::join(void** status) { mutex.lock(); if ((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) { mutex.unlock(); throw omni_thread_invalid(); } mutex.unlock(); if (this == self()) throw omni_thread_invalid(); if (detached) throw omni_thread_invalid(); DB(cerr << "omni_thread::join: doing WaitForSingleObject\n"); if (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0) throw omni_thread_fatal(GetLastError()); DB(cerr << "omni_thread::join: WaitForSingleObject succeeded\n"); if (status) *status = return_val; delete this; }
void omni_thread::join(void** status) { mutex.lock(); if ((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) { mutex.unlock(); throw omni_thread_invalid(); } mutex.unlock(); if (this == self()) throw omni_thread_invalid(); if (detached) throw omni_thread_invalid(); DB(cerr << "omni_thread::join: doing DosWaitThread\n"); APIRET rc = DosWaitThread( &handle , DCWW_WAIT ); if ( rc != 0 ) throw omni_thread_fatal(rc); DB(cerr << "omni_thread::join: DosWaitThread succeeded\n"); if (status) *status = return_val; delete this; }
void omni_thread::start(void) { omni_mutex_lock l(mutex); if (_state != STATE_NEW) throw omni_thread_invalid(); unsigned int t; handle = (HANDLE)_beginthreadex( NULL, 0, omni_thread_wrapper, (LPVOID)this, CREATE_SUSPENDED, &t); nt_id = t; if (handle == NULL) throw omni_thread_fatal(GetLastError()); if (!SetThreadPriority(handle, _priority)) throw omni_thread_fatal(GetLastError()); if (ResumeThread(handle) == 0xffffffff) throw omni_thread_fatal(GetLastError()); _state = STATE_RUNNING; }
omni_thread* omni_thread::create_dummy() { if (omni_thread::self()) throw omni_thread_invalid(); return new omni_thread_dummy; }
void omni_thread::start_undetached(void) { if ((fn_void != NULL) || (fn_ret != NULL)) throw omni_thread_invalid(); detached = 0; start(); }
void omni_thread::release_dummy() { omni_thread* self = omni_thread::self(); if (!self || !self->_dummy) throw omni_thread_invalid(); omni_thread_dummy* dummy = (omni_thread_dummy*)self; delete dummy; }
void omni_thread::set_priority(priority_t pri) { omni_mutex_lock l(mutex); if (_state != STATE_RUNNING) throw omni_thread_invalid(); _priority = pri; if (!SetThreadPriority(handle, nt_priority(pri))) throw omni_thread_fatal(GetLastError()); }
void omni_thread::set_priority(priority_t pri) { omni_mutex_lock l(mutex); if (_state != STATE_RUNNING) throw omni_thread_invalid(); _priority = pri; APIRET rc = DosSetPriority( PRTYS_THREAD , os2_priority(pri) , 0 , handle ); if ( rc != 0 ) throw omni_thread_fatal(rc); }
int omni_thread::os2_priority(priority_t pri) { switch (pri) { case PRIORITY_LOW: return PRTYC_IDLETIME; case PRIORITY_NORMAL: return PRTYC_REGULAR; case PRIORITY_HIGH: return PRTYC_FOREGROUNDSERVER; } throw omni_thread_invalid(); return 0; /* keep msvc++ happy */ }
int omni_thread::nt_priority(priority_t pri) { switch (pri) { case PRIORITY_LOW: return THREAD_PRIORITY_LOWEST; case PRIORITY_NORMAL: return THREAD_PRIORITY_NORMAL; case PRIORITY_HIGH: return THREAD_PRIORITY_HIGHEST; } throw omni_thread_invalid(); return 0; /* keep msvc++ happy */ }
void omni_thread::start(void) { omni_mutex_lock l(mutex); if (_state != STATE_NEW) throw omni_thread_invalid(); handle = _beginthread(omni_thread_wrapper,NULL,stack_size,(void*)this); if ( handle == -1 ) throw omni_thread_fatal(errno); APIRET rc = DosSetPriority( PRTYS_THREAD , os2_priority(_priority) , 0 , handle ); if ( rc != 0 ) throw omni_thread_fatal(rc); _state = STATE_RUNNING; }
void omni_thread::start(void) { omni_mutex_lock l(mutex); if (_state != STATE_NEW) throw omni_thread_invalid(); #ifndef __BCPLUSPLUS__ // MSVC++ or compatiable unsigned int t; handle = (HANDLE)_beginthreadex( NULL, 0, omni_thread_wrapper, (LPVOID)this, CREATE_SUSPENDED, &t); nt_id = t; if (handle == NULL) throw omni_thread_fatal(GetLastError()); #else // Borland C++ handle = (HANDLE)_beginthreadNT(omni_thread_wrapper, 0, (void*)this, NULL, CREATE_SUSPENDED, &nt_id); if (handle == INVALID_HANDLE_VALUE) throw omni_thread_fatal(errno); #endif if (!SetThreadPriority(handle, nt_priority(_priority))) throw omni_thread_fatal(GetLastError()); if (ResumeThread(handle) == 0xffffffff) throw omni_thread_fatal(GetLastError()); _state = STATE_RUNNING; }