aboutsummaryrefslogtreecommitdiff
path: root/C/Threads.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-06-21 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-12-17 14:59:19 +0500
commit5b39dc76f1bc82f941d5c800ab9f34407a06b53a (patch)
treefe5e17420300b715021a76328444088d32047963 /C/Threads.h
parent93be7d4abfd4233228f58ee1fbbcd76d91be66a4 (diff)
download7zip-23.01.tar.gz
7zip-23.01.tar.bz2
7zip-23.01.zip
23.0123.01
Diffstat (limited to 'C/Threads.h')
-rw-r--r--C/Threads.h50
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
22021-12-21 : Igor Pavlov : Public domain */ 22023-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
34typedef HANDLE CThread; 35typedef 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
55typedef DWORD_PTR CAffinityMask; 58typedef DWORD_PTR CAffinityMask;
56typedef DWORD_PTR CCpuSet; 59typedef 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
63typedef struct _CThread 66typedef 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)
71WRes Thread_Close(CThread *p); 74WRes Thread_Close(CThread *p);
72// #define Thread_Wait Thread_Wait_Close 75// #define Thread_Wait Thread_Wait_Close
73 76
74typedef void * THREAD_FUNC_RET_TYPE; 77typedef void * THREAD_FUNC_RET_TYPE;
78#define THREAD_FUNC_RET_ZERO NULL
79
75 80
76typedef UInt64 CAffinityMask; 81typedef UInt64 CAffinityMask;
77 82
78#ifdef _7ZIP_AFFINITY_SUPPORTED 83#ifdef Z7_AFFINITY_SUPPORTED
79 84
80typedef cpu_set_t CCpuSet; 85typedef 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
87typedef UInt64 CCpuSet; 92typedef 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);
187WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); 192WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);
188WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); 193WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);
189WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); 194WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);
195
190WRes Event_Set(CEvent *p); 196WRes Event_Set(CEvent *p);
191WRes Event_Reset(CEvent *p); 197WRes Event_Reset(CEvent *p);
192WRes Event_Wait(CEvent *p); 198WRes Event_Wait(CEvent *p);
@@ -227,6 +233,8 @@ LONG InterlockedIncrement(LONG volatile *addend);
227 233
228#endif // _WIN32 234#endif // _WIN32
229 235
236WRes AutoResetEvent_OptCreate_And_Reset(CAutoResetEvent *p);
237
230EXTERN_C_END 238EXTERN_C_END
231 239
232#endif 240#endif