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