1 /* Threads.h -- multithreading library
2 2017-06-18 : Igor Pavlov : Public domain */
15 WRes
HandlePtr_Close(HANDLE
*h
);
16 WRes
Handle_WaitObject(HANDLE h
);
18 typedef 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))
32 #define THREAD_FUNC_CALL_TYPE MY_STD_CALL
33 #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
34 typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE
* THREAD_FUNC_TYPE
)(void *);
35 WRes
Thread_Create(CThread
*p
, THREAD_FUNC_TYPE func
, LPVOID param
);
37 typedef HANDLE CEvent
;
38 typedef CEvent CAutoResetEvent
;
39 typedef 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))
44 WRes
Event_Set(CEvent
*p
);
45 WRes
Event_Reset(CEvent
*p
);
46 WRes
ManualResetEvent_Create(CManualResetEvent
*p
, int signaled
);
47 WRes
ManualResetEvent_CreateNotSignaled(CManualResetEvent
*p
);
48 WRes
AutoResetEvent_Create(CAutoResetEvent
*p
, int signaled
);
49 WRes
AutoResetEvent_CreateNotSignaled(CAutoResetEvent
*p
);
51 typedef HANDLE CSemaphore
;
52 #define Semaphore_Construct(p) *(p) = NULL
53 #define Semaphore_IsCreated(p) (*(p) != NULL)
54 #define Semaphore_Close(p) HandlePtr_Close(p)
55 #define Semaphore_Wait(p) Handle_WaitObject(*(p))
56 WRes
Semaphore_Create(CSemaphore
*p
, UInt32 initCount
, UInt32 maxCount
);
57 WRes
Semaphore_ReleaseN(CSemaphore
*p
, UInt32 num
);
58 WRes
Semaphore_Release1(CSemaphore
*p
);
60 typedef CRITICAL_SECTION CCriticalSection
;
61 WRes
CriticalSection_Init(CCriticalSection
*p
);
62 #define CriticalSection_Delete(p) DeleteCriticalSection(p)
63 #define CriticalSection_Enter(p) EnterCriticalSection(p)
64 #define CriticalSection_Leave(p) LeaveCriticalSection(p)