src/third-party/lzma/Threads.h (view raw)
1/* Threads.h -- multithreading library
22013-11-12 : Igor Pavlov : Public domain */
3
4#ifndef __7Z_THREADS_H
5#define __7Z_THREADS_H
6
7#ifdef _WIN32
8#include <windows.h>
9#endif
10
11#include "7zTypes.h"
12
13EXTERN_C_BEGIN
14
15WRes HandlePtr_Close(HANDLE *h);
16WRes Handle_WaitObject(HANDLE h);
17
18typedef HANDLE CThread;
19#define Thread_Construct(p) *(p) = NULL
20#define Thread_WasCreated(p) (*(p) != NULL)
21#define Thread_Close(p) HandlePtr_Close(p)
22#define Thread_Wait(p) Handle_WaitObject(*(p))
23
24typedef
25#ifdef UNDER_CE
26 DWORD
27#else
28 unsigned
29#endif
30 THREAD_FUNC_RET_TYPE;
31
32#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
33#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
34typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *);
35WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param);
36
37typedef HANDLE CEvent;
38typedef CEvent CAutoResetEvent;
39typedef CEvent CManualResetEvent;
40#define Event_Construct(p) *(p) = NULL
41#define Event_IsCreated(p) (*(p) != NULL)
42#define Event_Close(p) HandlePtr_Close(p)
43#define Event_Wait(p) Handle_WaitObject(*(p))
44WRes Event_Set(CEvent *p);
45WRes Event_Reset(CEvent *p);
46WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled);
47WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);
48WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);
49WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);
50
51typedef HANDLE CSemaphore;
52#define Semaphore_Construct(p) (*p) = NULL
53#define Semaphore_Close(p) HandlePtr_Close(p)
54#define Semaphore_Wait(p) Handle_WaitObject(*(p))
55WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
56WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
57WRes Semaphore_Release1(CSemaphore *p);
58
59typedef CRITICAL_SECTION CCriticalSection;
60WRes CriticalSection_Init(CCriticalSection *p);
61#define CriticalSection_Delete(p) DeleteCriticalSection(p)
62#define CriticalSection_Enter(p) EnterCriticalSection(p)
63#define CriticalSection_Leave(p) LeaveCriticalSection(p)
64
65EXTERN_C_END
66
67#endif