other-licenses/7zstub/src/Windows/Thread.h

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:5c4f778652bd
1 // Windows/Thread.h
2
3 #ifndef __WINDOWS_THREAD_H
4 #define __WINDOWS_THREAD_H
5
6 #include "Handle.h"
7 #include "Defs.h"
8
9 namespace NWindows {
10
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 }
28
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)); }
35
36 int GetPriority()
37 { return ::GetThreadPriority(_handle); }
38 bool SetPriority(int priority)
39 { return BOOLToBool(::SetThreadPriority(_handle, priority)); }
40
41 bool Wait()
42 {
43 if (!IsOpen())
44 return true;
45 return (::WaitForSingleObject(_handle, INFINITE) == WAIT_OBJECT_0);
46 }
47
48 };
49
50 }
51
52 #endif

mercurial