diff options
Diffstat (limited to 'C/Threads.h')
-rw-r--r-- | C/Threads.h | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/C/Threads.h b/C/Threads.h index 89ecb92..4028464 100644 --- a/C/Threads.h +++ b/C/Threads.h | |||
@@ -1,18 +1,19 @@ | |||
1 | /* Threads.h -- multithreading library | 1 | /* Threads.h -- multithreading library |
2 | 2021-12-21 : Igor Pavlov : Public domain */ | 2 | 2023-04-02 : Igor Pavlov : Public domain */ |
3 | 3 | ||
4 | #ifndef __7Z_THREADS_H | 4 | #ifndef ZIP7_INC_THREADS_H |
5 | #define __7Z_THREADS_H | 5 | #define ZIP7_INC_THREADS_H |
6 | 6 | ||
7 | #ifdef _WIN32 | 7 | #ifdef _WIN32 |
8 | #include <Windows.h> | 8 | #include "7zWindows.h" |
9 | |||
9 | #else | 10 | #else |
10 | 11 | ||
11 | #if defined(__linux__) | 12 | #if defined(__linux__) |
12 | #if !defined(__APPLE__) && !defined(_AIX) && !defined(__ANDROID__) | 13 | #if !defined(__APPLE__) && !defined(_AIX) && !defined(__ANDROID__) |
13 | #ifndef _7ZIP_AFFINITY_DISABLE | 14 | #ifndef Z7_AFFINITY_DISABLE |
14 | #define _7ZIP_AFFINITY_SUPPORTED | 15 | #define Z7_AFFINITY_SUPPORTED |
15 | // #pragma message(" ==== _7ZIP_AFFINITY_SUPPORTED") | 16 | // #pragma message(" ==== Z7_AFFINITY_SUPPORTED") |
16 | // #define _GNU_SOURCE | 17 | // #define _GNU_SOURCE |
17 | #endif | 18 | #endif |
18 | #endif | 19 | #endif |
@@ -33,7 +34,7 @@ WRes Handle_WaitObject(HANDLE h); | |||
33 | 34 | ||
34 | typedef HANDLE CThread; | 35 | typedef HANDLE CThread; |
35 | 36 | ||
36 | #define Thread_Construct(p) { *(p) = NULL; } | 37 | #define Thread_CONSTRUCT(p) { *(p) = NULL; } |
37 | #define Thread_WasCreated(p) (*(p) != NULL) | 38 | #define Thread_WasCreated(p) (*(p) != NULL) |
38 | #define Thread_Close(p) HandlePtr_Close(p) | 39 | #define Thread_Close(p) HandlePtr_Close(p) |
39 | // #define Thread_Wait(p) Handle_WaitObject(*(p)) | 40 | // #define Thread_Wait(p) Handle_WaitObject(*(p)) |
@@ -52,42 +53,46 @@ typedef | |||
52 | #endif | 53 | #endif |
53 | THREAD_FUNC_RET_TYPE; | 54 | THREAD_FUNC_RET_TYPE; |
54 | 55 | ||
56 | #define THREAD_FUNC_RET_ZERO 0 | ||
57 | |||
55 | typedef DWORD_PTR CAffinityMask; | 58 | typedef DWORD_PTR CAffinityMask; |
56 | typedef DWORD_PTR CCpuSet; | 59 | typedef DWORD_PTR CCpuSet; |
57 | 60 | ||
58 | #define CpuSet_Zero(p) { *(p) = 0; } | 61 | #define CpuSet_Zero(p) *(p) = (0) |
59 | #define CpuSet_Set(p, cpu) { *(p) |= ((DWORD_PTR)1 << (cpu)); } | 62 | #define CpuSet_Set(p, cpu) *(p) |= ((DWORD_PTR)1 << (cpu)) |
60 | 63 | ||
61 | #else // _WIN32 | 64 | #else // _WIN32 |
62 | 65 | ||
63 | typedef struct _CThread | 66 | typedef struct |
64 | { | 67 | { |
65 | pthread_t _tid; | 68 | pthread_t _tid; |
66 | int _created; | 69 | int _created; |
67 | } CThread; | 70 | } CThread; |
68 | 71 | ||
69 | #define Thread_Construct(p) { (p)->_tid = 0; (p)->_created = 0; } | 72 | #define Thread_CONSTRUCT(p) { (p)->_tid = 0; (p)->_created = 0; } |
70 | #define Thread_WasCreated(p) ((p)->_created != 0) | 73 | #define Thread_WasCreated(p) ((p)->_created != 0) |
71 | WRes Thread_Close(CThread *p); | 74 | WRes Thread_Close(CThread *p); |
72 | // #define Thread_Wait Thread_Wait_Close | 75 | // #define Thread_Wait Thread_Wait_Close |
73 | 76 | ||
74 | typedef void * THREAD_FUNC_RET_TYPE; | 77 | typedef void * THREAD_FUNC_RET_TYPE; |
78 | #define THREAD_FUNC_RET_ZERO NULL | ||
79 | |||
75 | 80 | ||
76 | typedef UInt64 CAffinityMask; | 81 | typedef UInt64 CAffinityMask; |
77 | 82 | ||
78 | #ifdef _7ZIP_AFFINITY_SUPPORTED | 83 | #ifdef Z7_AFFINITY_SUPPORTED |
79 | 84 | ||
80 | typedef cpu_set_t CCpuSet; | 85 | typedef cpu_set_t CCpuSet; |
81 | #define CpuSet_Zero(p) CPU_ZERO(p) | 86 | #define CpuSet_Zero(p) CPU_ZERO(p) |
82 | #define CpuSet_Set(p, cpu) CPU_SET(cpu, p) | 87 | #define CpuSet_Set(p, cpu) CPU_SET(cpu, p) |
83 | #define CpuSet_IsSet(p, cpu) CPU_ISSET(cpu, p) | 88 | #define CpuSet_IsSet(p, cpu) CPU_ISSET(cpu, p) |
84 | 89 | ||
85 | #else | 90 | #else |
86 | 91 | ||
87 | typedef UInt64 CCpuSet; | 92 | typedef UInt64 CCpuSet; |
88 | #define CpuSet_Zero(p) { *(p) = 0; } | 93 | #define CpuSet_Zero(p) *(p) = (0) |
89 | #define CpuSet_Set(p, cpu) { *(p) |= ((UInt64)1 << (cpu)); } | 94 | #define CpuSet_Set(p, cpu) *(p) |= ((UInt64)1 << (cpu)) |
90 | #define CpuSet_IsSet(p, cpu) ((*(p) & ((UInt64)1 << (cpu))) != 0) | 95 | #define CpuSet_IsSet(p, cpu) ((*(p) & ((UInt64)1 << (cpu))) != 0) |
91 | 96 | ||
92 | #endif | 97 | #endif |
93 | 98 | ||
@@ -95,7 +100,7 @@ typedef UInt64 CCpuSet; | |||
95 | #endif // _WIN32 | 100 | #endif // _WIN32 |
96 | 101 | ||
97 | 102 | ||
98 | #define THREAD_FUNC_CALL_TYPE MY_STD_CALL | 103 | #define THREAD_FUNC_CALL_TYPE Z7_STDCALL |
99 | 104 | ||
100 | #if defined(_WIN32) && defined(__GNUC__) | 105 | #if defined(_WIN32) && defined(__GNUC__) |
101 | /* GCC compiler for x86 32-bit uses the rule: | 106 | /* GCC compiler for x86 32-bit uses the rule: |
@@ -187,6 +192,7 @@ WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); | |||
187 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); | 192 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); |
188 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); | 193 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); |
189 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); | 194 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); |
195 | |||
190 | WRes Event_Set(CEvent *p); | 196 | WRes Event_Set(CEvent *p); |
191 | WRes Event_Reset(CEvent *p); | 197 | WRes Event_Reset(CEvent *p); |
192 | WRes Event_Wait(CEvent *p); | 198 | WRes Event_Wait(CEvent *p); |
@@ -227,6 +233,8 @@ LONG InterlockedIncrement(LONG volatile *addend); | |||
227 | 233 | ||
228 | #endif // _WIN32 | 234 | #endif // _WIN32 |
229 | 235 | ||
236 | WRes AutoResetEvent_OptCreate_And_Reset(CAutoResetEvent *p); | ||
237 | |||
230 | EXTERN_C_END | 238 | EXTERN_C_END |
231 | 239 | ||
232 | #endif | 240 | #endif |