Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 // Windows/Thread.h
3 #ifndef __WINDOWS_THREAD_H
4 #define __WINDOWS_THREAD_H
6 #include "Handle.h"
7 #include "Defs.h"
9 namespace NWindows {
11 class CThread: public CHandle
12 {
13 bool IsOpen() const { return _handle != 0; }
14 public:
15 bool Create(LPSECURITY_ATTRIBUTES threadAttributes,
16 SIZE_T stackSize, LPTHREAD_START_ROUTINE startAddress,
17 LPVOID parameter, DWORD creationFlags, LPDWORD threadId)
18 {
19 _handle = ::CreateThread(threadAttributes, stackSize, startAddress,
20 parameter, creationFlags, threadId);
21 return (_handle != NULL);
22 }
23 bool Create(LPTHREAD_START_ROUTINE startAddress, LPVOID parameter)
24 {
25 DWORD threadId;
26 return Create(NULL, 0, startAddress, parameter, 0, &threadId);
27 }
29 DWORD Resume()
30 { return ::ResumeThread(_handle); }
31 DWORD Suspend()
32 { return ::SuspendThread(_handle); }
33 bool Terminate(DWORD exitCode)
34 { return BOOLToBool(::TerminateThread(_handle, exitCode)); }
36 int GetPriority()
37 { return ::GetThreadPriority(_handle); }
38 bool SetPriority(int priority)
39 { return BOOLToBool(::SetThreadPriority(_handle, priority)); }
41 bool Wait()
42 {
43 if (!IsOpen())
44 return true;
45 return (::WaitForSingleObject(_handle, INFINITE) == WAIT_OBJECT_0);
46 }
48 };
50 }
52 #endif