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
10namespace NWindows {
11
12class CThread
13{
14  ::CThread thread;
15public:
16  CThread() { Thread_Construct(&thread); }
17  ~CThread() { Close(); }
18  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }
19  WRes Close()  { return Thread_Close(&thread); }
20  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
21    { return Thread_Create(&thread, startAddress, parameter); }
22  WRes Wait() { return Thread_Wait(&thread); }
23
24  #ifdef _WIN32
25  operator HANDLE() { return thread; }
26  void Attach(HANDLE handle) { thread = handle; }
27  HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; }
28  DWORD Resume() { return ::ResumeThread(thread); }
29  DWORD Suspend() { return ::SuspendThread(thread); }
30  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); }
31  int GetPriority() { return ::GetThreadPriority(thread); }
32  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); }
33  #endif
34};
35
36}
37
38#endif
39