30 #ifdef OVR_ENABLE_THREADS
95 pthread_mutex_init(&
SMutex, 0);
100 pthread_mutex_destroy(&
SMutex);
107 while (pthread_mutex_lock(&
SMutex))
115 if (!pthread_mutex_trylock(&
SMutex))
134 pthread_mutex_unlock(&
SMutex);
256 pthread_mutex_init(&
SMutex, 0);
257 pthread_cond_init(&
Condv, 0);
262 pthread_mutex_destroy(&
SMutex);
263 pthread_cond_destroy(&
Condv);
275 pthread_mutex_lock(&
SMutex);
282 for(
unsigned i=0; i<lockCount; i++)
301 gettimeofday(&tv, 0);
317 pthread_mutex_unlock(&
SMutex);
320 for(
unsigned i=0; i<lockCount; i++)
330 pthread_mutex_lock(&
SMutex);
331 pthread_cond_signal(&
Condv);
332 pthread_mutex_unlock(&
SMutex);
338 pthread_mutex_lock(&
SMutex);
339 pthread_cond_broadcast(&
Condv);
340 pthread_mutex_unlock(&
SMutex);
405 CreateParams params(threadFunction, userHandle, stackSize, processor, initialState);
480 return (((
size_t)ptr) >> 6) ^ (size_t)ptr;
651 int result = pthread->
PRun();
657 return reinterpret_cast<void*
>(result);
677 OVR_DEBUG_LOG((
"Thread::Start failed - thread %p already running",
this));
683 pthread_attr_init(&
Attr);
684 pthread_attr_setdetachstate(&
Attr, PTHREAD_CREATE_DETACHED);
685 pthread_attr_setstacksize(&
Attr, 128 * 1024);
688 pthread_attr_setschedparam(&
Attr, &sparam);
705 pthread_attr_init(&attr);
706 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
707 pthread_attr_setstacksize(&attr,
StackSize);
710 pthread_attr_setschedparam(&attr, &sparam);
712 pthread_attr_destroy(&attr);
731 OVR_DEBUG_LOG((
"Thread::Suspend - cannot suspend threads on this system"));
756 pthread_exit(reinterpret_cast<void*>(exitCode));
761 return (
void*)pthread_self();
787 #endif // OVR_ENABLE_THREADS
#define OVR_WAIT_INFINITE
static bool RecursiveAttrInit
MutexImpl(Mutex *pmutex, bool recursive=1)
void * Thread_PthreadStartFn(void *phandle)
AtomicInt< SInt32 > SuspendCount
static void OVR_CDECL FinishAllThreads()
static bool MSleep(unsigned msecs)
void addThread(Thread *pthread)
bool IsLockedByAnotherThread()
WaitCondition StateWaitCondition
static void AddRunningThread(Thread *pthread)
static pthread_attr_t Attr
bool Wait(unsigned delay=OVR_WAIT_INFINITE)
ThreadState GetThreadState() const
bool IsLockedByAnotherThread(Mutex *pmutex)
void removeThread(Thread *pthread)
#define OVR_THREAD_START_SUSPENDED
static pthread_mutexattr_t RecursiveAttr
static ThreadList *volatile pRunningThreads
void updateState(bool newState, bool newTemp, bool mustNotify)
Thread(UPInt stackSize=128 *1024, int processor=-1)
size_t operator()(const Thread *ptr)
virtual void Exit(int exitCode=0)
static bool Sleep(unsigned secs)
static int GetOSPriority(ThreadPriority)
static void RemoveRunningThread(Thread *pthread)
WaitConditionImpl * pImpl
void Unlock(Mutex *pmutex)
HashSet< Thread *, ThreadHashOp > ThreadSet
friend class WaitConditionImpl
virtual bool Start(ThreadState initialState=Running)
__syscall_slong_t tv_nsec
static void FinishAllThreads()
void SetExitFlag(bool exitFlag)
WaitCondition ThreadsEmpty
#define OVR_DEBUG_LOG(args)
AtomicInt< UInt32 > ThreadFlags
void Init(const CreateParams ¶ms)
#define OVR_THREAD_STARTED
#define OVR_THREAD_FINISHED
ThreadId GetCurrentThreadId()
bool Wait(Mutex *pmutex, unsigned delay=OVR_WAIT_INFINITE)
bool Wait(Mutex *pmutex, unsigned delay=OVR_WAIT_INFINITE)
union pthread_attr_t pthread_attr_t
friend void * Thread_PthreadStartFn(void *phandle)
int(* ThreadFn)(Thread *pthread, void *h)
unsigned long int pthread_t