diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/Thread.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/Thread.h')
-rw-r--r-- | CPP/Windows/Thread.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h new file mode 100644 index 0000000..5fca173 --- /dev/null +++ b/CPP/Windows/Thread.h | |||
@@ -0,0 +1,44 @@ | |||
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 MY_UNCOPYABLE | ||
13 | { | ||
14 | ::CThread thread; | ||
15 | public: | ||
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 Wait() { return Thread_Wait(&thread); } | ||
21 | WRes Wait_Close() { return Thread_Wait_Close(&thread); } | ||
22 | |||
23 | WRes Create(THREAD_FUNC_TYPE startAddress, LPVOID param) | ||
24 | { return Thread_Create(&thread, startAddress, param); } | ||
25 | WRes Create_With_Affinity(THREAD_FUNC_TYPE startAddress, LPVOID param, CAffinityMask affinity) | ||
26 | { return Thread_Create_With_Affinity(&thread, startAddress, param, affinity); } | ||
27 | WRes Create_With_CpuSet(THREAD_FUNC_TYPE startAddress, LPVOID param, const CCpuSet *cpuSet) | ||
28 | { return Thread_Create_With_CpuSet(&thread, startAddress, param, cpuSet); } | ||
29 | |||
30 | #ifdef _WIN32 | ||
31 | operator HANDLE() { return thread; } | ||
32 | void Attach(HANDLE handle) { thread = handle; } | ||
33 | HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; } | ||
34 | DWORD Resume() { return ::ResumeThread(thread); } | ||
35 | DWORD Suspend() { return ::SuspendThread(thread); } | ||
36 | bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); } | ||
37 | int GetPriority() { return ::GetThreadPriority(thread); } | ||
38 | bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); } | ||
39 | #endif | ||
40 | }; | ||
41 | |||
42 | } | ||
43 | |||
44 | #endif | ||