1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// Windows/Thread.h
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __WINDOWS_THREAD_H
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __WINDOWS_THREAD_H
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../C/Threads.h"
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Defs.h"
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
10baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NWindows {
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
12baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CThread
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ::CThread thread;
15baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CThread() { Thread_Construct(&thread); }
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ~CThread() { Close(); }
18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  WRes Close()  { return Thread_Close(&thread); }
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { return Thread_Create(&thread, startAddress, parameter); }
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  WRes Wait() { return Thread_Wait(&thread); }
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #ifdef _WIN32
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  operator HANDLE() { return thread; }
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Attach(HANDLE handle) { thread = handle; }
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; }
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  DWORD Resume() { return ::ResumeThread(thread); }
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  DWORD Suspend() { return ::SuspendThread(thread); }
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); }
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int GetPriority() { return ::GetThreadPriority(thread); }
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); }
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #endif
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
39