• 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
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); }
Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * startAddress)(void *),LPVOID parameter)20   WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
21     { return Thread_Create(&thread, startAddress, parameter); }
Wait()22   WRes Wait() { return Thread_Wait(&thread); }
23 
24   #ifdef _WIN32
HANDLE()25   operator HANDLE() { return thread; }
Attach(HANDLE handle)26   void Attach(HANDLE handle) { thread = handle; }
Detach()27   HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; }
Resume()28   DWORD Resume() { return ::ResumeThread(thread); }
Suspend()29   DWORD Suspend() { return ::SuspendThread(thread); }
Terminate(DWORD exitCode)30   bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); }
GetPriority()31   int GetPriority() { return ::GetThreadPriority(thread); }
SetPriority(int priority)32   bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); }
33   #endif
34 };
35 
36 }
37 
38 #endif
39