rlm@1
|
1 /* Threads.h -- multithreading library
|
rlm@1
|
2 2008-11-22 : Igor Pavlov : Public domain */
|
rlm@1
|
3
|
rlm@1
|
4 #ifndef __7Z_THRESDS_H
|
rlm@1
|
5 #define __7Z_THRESDS_H
|
rlm@1
|
6
|
rlm@1
|
7 #include "Types.h"
|
rlm@1
|
8
|
rlm@1
|
9 typedef struct _CThread
|
rlm@1
|
10 {
|
rlm@1
|
11 HANDLE handle;
|
rlm@1
|
12 } CThread;
|
rlm@1
|
13
|
rlm@1
|
14 #define Thread_Construct(thread) (thread)->handle = NULL
|
rlm@1
|
15 #define Thread_WasCreated(thread) ((thread)->handle != NULL)
|
rlm@1
|
16
|
rlm@1
|
17 typedef unsigned THREAD_FUNC_RET_TYPE;
|
rlm@1
|
18 #define THREAD_FUNC_CALL_TYPE MY_STD_CALL
|
rlm@1
|
19 #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
|
rlm@1
|
20
|
rlm@1
|
21 WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
|
rlm@1
|
22 WRes Thread_Wait(CThread *thread);
|
rlm@1
|
23 WRes Thread_Close(CThread *thread);
|
rlm@1
|
24
|
rlm@1
|
25 typedef struct _CEvent
|
rlm@1
|
26 {
|
rlm@1
|
27 HANDLE handle;
|
rlm@1
|
28 } CEvent;
|
rlm@1
|
29
|
rlm@1
|
30 typedef CEvent CAutoResetEvent;
|
rlm@1
|
31 typedef CEvent CManualResetEvent;
|
rlm@1
|
32
|
rlm@1
|
33 #define Event_Construct(event) (event)->handle = NULL
|
rlm@1
|
34 #define Event_IsCreated(event) ((event)->handle != NULL)
|
rlm@1
|
35
|
rlm@1
|
36 WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
|
rlm@1
|
37 WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
|
rlm@1
|
38 WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
|
rlm@1
|
39 WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
|
rlm@1
|
40 WRes Event_Set(CEvent *event);
|
rlm@1
|
41 WRes Event_Reset(CEvent *event);
|
rlm@1
|
42 WRes Event_Wait(CEvent *event);
|
rlm@1
|
43 WRes Event_Close(CEvent *event);
|
rlm@1
|
44
|
rlm@1
|
45
|
rlm@1
|
46 typedef struct _CSemaphore
|
rlm@1
|
47 {
|
rlm@1
|
48 HANDLE handle;
|
rlm@1
|
49 } CSemaphore;
|
rlm@1
|
50
|
rlm@1
|
51 #define Semaphore_Construct(p) (p)->handle = NULL
|
rlm@1
|
52
|
rlm@1
|
53 WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
|
rlm@1
|
54 WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
|
rlm@1
|
55 WRes Semaphore_Release1(CSemaphore *p);
|
rlm@1
|
56 WRes Semaphore_Wait(CSemaphore *p);
|
rlm@1
|
57 WRes Semaphore_Close(CSemaphore *p);
|
rlm@1
|
58
|
rlm@1
|
59
|
rlm@1
|
60 typedef CRITICAL_SECTION CCriticalSection;
|
rlm@1
|
61
|
rlm@1
|
62 WRes CriticalSection_Init(CCriticalSection *p);
|
rlm@1
|
63 #define CriticalSection_Delete(p) DeleteCriticalSection(p)
|
rlm@1
|
64 #define CriticalSection_Enter(p) EnterCriticalSection(p)
|
rlm@1
|
65 #define CriticalSection_Leave(p) LeaveCriticalSection(p)
|
rlm@1
|
66
|
rlm@1
|
67 #endif
|
rlm@1
|
68
|