Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_THREADMANAGER_H__
00009 #define __SP_THREADMANAGER_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #if defined(SP_PLATFORM_WINDOWS)
00015 # include <windows.h>
00016 # include <process.h>
00017 #elif defined(SP_PLATFORM_LINUX) || defined(SP_PLATFORM_IOS)
00018 # include <pthread.h>
00019 #endif
00020
00021
00022 namespace sp
00023 {
00024
00025
00026 #if defined(SP_PLATFORM_WINDOWS)
00027
00028 typedef DWORD (WINAPI *PFNTHREADPROC)(void* Arguments);
00029 #define THREAD_PROC(n) DWORD WINAPI n(void* Arguments)
00030
00031 #else
00032
00033 typedef void* (*PFNTHREADPROC)(void* Arguments);
00034 #define THREAD_PROC(n) void* n(void* Arguments)
00035
00036 #endif
00037
00038
00040 enum EThreadPriorityClasses
00041 {
00042 THREADPRIORITY_LOW,
00043 THREADPRIORITY_NORMAL,
00044 THREADPRIORITY_HIGH,
00045 };
00046
00047
00049 class SP_EXPORT ThreadManager
00050 {
00051
00052 public:
00053
00054 ThreadManager(PFNTHREADPROC ThreadProc, void* Arguments = 0, bool StartImmediately = true);
00055 ~ThreadManager();
00056
00057
00058
00060 bool running() const;
00061
00063 void pause();
00064
00066 void resume();
00067
00069 void terminate();
00070
00072 void setPriority(const EThreadPriorityClasses PriorityClass);
00073
00074 private:
00075
00076
00077
00078 #if defined(SP_PLATFORM_WINDOWS)
00079 HANDLE ThreadHandle_;
00080 #elif defined(SP_PLATFORM_LINUX) || defined(SP_PLATFORM_IOS)
00081 pthread_t ThreadHandle_;
00082 #endif
00083
00084 };
00085
00086
00087 }
00088
00089
00090 #endif
00091
00092
00093
00094