• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Windows/Thread.h
2 
3 #ifndef __WINDOWS_THREAD_H
4 #define __WINDOWS_THREAD_H
5 
6 #include "../../C/Threads.h"
7 
8 #include "Defs.h"
9 
10 namespace NWindows {
11 
12 class CThread  MY_UNCOPYABLE
13 {
14   ::CThread thread;
15 public:
CThread()16   CThread() { Thread_Construct(&thread); }
~CThread()17   ~CThread() { Close(); }
IsCreated()18   bool IsCreated() { return Thread_WasCreated(&thread) != 0; }
Close()19   WRes Close()  { return Thread_Close(&thread); }
20   // WRes Wait() { return Thread_Wait(&thread); }
Wait_Close()21   WRes Wait_Close() { return Thread_Wait_Close(&thread); }
22 
Create(THREAD_FUNC_TYPE startAddress,LPVOID param)23   WRes Create(THREAD_FUNC_TYPE startAddress, LPVOID param)
24     { return Thread_Create(&thread, startAddress, param); }
Create_With_Affinity(THREAD_FUNC_TYPE startAddress,LPVOID param,CAffinityMask affinity)25   WRes Create_With_Affinity(THREAD_FUNC_TYPE startAddress, LPVOID param, CAffinityMask affinity)
26     { return Thread_Create_With_Affinity(&thread, startAddress, param, affinity); }
Create_With_CpuSet(THREAD_FUNC_TYPE startAddress,LPVOID param,const CCpuSet * cpuSet)27   WRes Create_With_CpuSet(THREAD_FUNC_TYPE startAddress, LPVOID param, const CCpuSet *cpuSet)
28     { return Thread_Create_With_CpuSet(&thread, startAddress, param, cpuSet); }
29 
30   #ifdef _WIN32
HANDLE()31   operator HANDLE() { return thread; }
Attach(HANDLE handle)32   void Attach(HANDLE handle) { thread = handle; }
Detach()33   HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; }
Resume()34   DWORD Resume() { return ::ResumeThread(thread); }
Suspend()35   DWORD Suspend() { return ::SuspendThread(thread); }
Terminate(DWORD exitCode)36   bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); }
GetPriority()37   int GetPriority() { return ::GetThreadPriority(thread); }
SetPriority(int priority)38   bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); }
39   #endif
40 };
41 
42 }
43 
44 #endif
45