diff options
author | Brad Davis <[email protected]> | 2014-07-24 16:47:31 -0700 |
---|---|---|
committer | Brad Davis <[email protected]> | 2014-07-24 16:47:31 -0700 |
commit | 0f49ce8fc6aa54224e4c0d6fda8c4527ad39cce1 (patch) | |
tree | da07ebc6a7f75185bda857dd5f1c34710b416a93 /LibOVR/Src/Kernel/OVR_Threads.h | |
parent | ca79271759ff7eecd22ec5c4db438370fe51d687 (diff) |
0.4 Win-Beta0.4.0
Diffstat (limited to 'LibOVR/Src/Kernel/OVR_Threads.h')
-rw-r--r-- | LibOVR/Src/Kernel/OVR_Threads.h | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/LibOVR/Src/Kernel/OVR_Threads.h b/LibOVR/Src/Kernel/OVR_Threads.h index 307f107..0ecc152 100644 --- a/LibOVR/Src/Kernel/OVR_Threads.h +++ b/LibOVR/Src/Kernel/OVR_Threads.h @@ -196,9 +196,7 @@ typedef void* ThreadId; class Thread : public RefCountBase<Thread> { // NOTE: Waitable must be the first base since it implements RefCountImpl. - public: - // *** Callback functions, can be used instead of overriding Run // Run function prototypes. @@ -234,30 +232,31 @@ public: // Thread constructor parameters struct CreateParams { - CreateParams(ThreadFn func = 0, void* hand = 0, UPInt ssize = 128 * 1024, + CreateParams(ThreadFn func = 0, void* hand = 0, size_t ssize = 128 * 1024, int proc = -1, ThreadState state = NotRunning, ThreadPriority prior = NormalPriority) : threadFunction(func), userHandle(hand), stackSize(ssize), processor(proc), initialState(state), priority(prior) {} ThreadFn threadFunction; // Thread function void* userHandle; // User handle passes to a thread - UPInt stackSize; // Thread stack size + size_t stackSize; // Thread stack size int processor; // Thread hardware processor ThreadState initialState; // ThreadPriority priority; // Thread priority }; + // *** Constructors // A default constructor always creates a thread in NotRunning state, because // the derived class has not yet been initialized. The derived class can call Start explicitly. // "processor" parameter specifies which hardware processor this thread will be run on. // -1 means OS decides this. Implemented only on Win32 - Thread(UPInt stackSize = 128 * 1024, int processor = -1); + Thread(size_t stackSize = 128 * 1024, int processor = -1); // Constructors that initialize the thread with a pointer to function. // An option to start a thread is available, but it should not be used if classes are derived from Thread. // "processor" parameter specifies which hardware processor this thread will be run on. // -1 means OS decides this. Implemented only on Win32 - Thread(ThreadFn threadFunction, void* userHandle = 0, UPInt stackSize = 128 * 1024, + Thread(ThreadFn threadFunction, void* userHandle = 0, size_t stackSize = 128 * 1024, int processor = -1, ThreadState initialState = NotRunning); // Constructors that initialize the thread with a create parameters structure. explicit Thread(const CreateParams& params); @@ -314,6 +313,11 @@ public: // Returns current thread state ThreadState GetThreadState() const; + // Wait for thread to finish for a maxmimum number of milliseconds + // For maxWaitMs = 0 it simply polls and then returns if the thread is not finished + // For maxWaitMs < 0 it will wait forever + bool Join(int maxWaitMs = -1) const; + // Returns the number of available CPUs on the system static int GetCPUCount(); @@ -321,13 +325,13 @@ public: // and set to the return value if Run function after the thread is finished. inline int GetExitCode() const { return ExitCode; } // Returns an OS handle -#if defined(OVR_OS_WIN32) +#if defined(OVR_OS_WIN32) void* GetOSHandle() const { return ThreadHandle; } #else pthread_t GetOSHandle() const { return ThreadHandle; } #endif -#if defined(OVR_OS_WIN32) +#if defined(OVR_OS_WIN32) ThreadId GetThreadId() const { return IdValue; } #else ThreadId GetThreadId() const { return (ThreadId)GetOSHandle(); } @@ -343,16 +347,11 @@ public: // *** Debugging functionality -#if defined(OVR_OS_WIN32) virtual void SetThreadName( const char* name ); -#else - virtual void SetThreadName( const char* name ) { OVR_UNUSED(name); } -#endif private: #if defined(OVR_OS_WIN32) - friend unsigned WINAPI Thread_Win32StartFn(void *pthread); - + friend unsigned WINAPI Thread_Win32StartFn(void *phandle); #else friend void *Thread_PthreadStartFn(void * phandle); @@ -362,15 +361,15 @@ private: protected: // Thread state flags - AtomicInt<UInt32> ThreadFlags; - AtomicInt<SInt32> SuspendCount; - UPInt StackSize; + AtomicInt<uint32_t> ThreadFlags; + AtomicInt<int32_t> SuspendCount; + size_t StackSize; // Hardware processor which this thread is running on. int Processor; ThreadPriority Priority; -#if defined(OVR_OS_WIN32) +#if defined(OVR_OS_WIN32) void* ThreadHandle; volatile ThreadId IdValue; |