1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* Threads.h -- multithreading library 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync2009-03-27 : Igor Pavlov : Public domain */ 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __7Z_THREADS_H 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __7Z_THREADS_H 6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Types.h" 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef __cplusplus 10baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern "C" { 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 13baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes HandlePtr_Close(HANDLE *h); 14baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Handle_WaitObject(HANDLE h); 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 16baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef HANDLE CThread; 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Thread_Construct(p) *(p) = NULL 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Thread_WasCreated(p) (*(p) != NULL) 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Thread_Close(p) HandlePtr_Close(p) 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Thread_Wait(p) Handle_WaitObject(*(p)) 21baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef unsigned THREAD_FUNC_RET_TYPE; 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define THREAD_FUNC_CALL_TYPE MY_STD_CALL 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE 24baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *); 25baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param); 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 27baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef HANDLE CEvent; 28baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CEvent CAutoResetEvent; 29baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CEvent CManualResetEvent; 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Event_Construct(p) *(p) = NULL 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Event_IsCreated(p) (*(p) != NULL) 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Event_Close(p) HandlePtr_Close(p) 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Event_Wait(p) Handle_WaitObject(*(p)) 34baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Event_Set(CEvent *p); 35baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Event_Reset(CEvent *p); 36baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); 37baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); 38baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); 39baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); 40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 41baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef HANDLE CSemaphore; 42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Semaphore_Construct(p) (*p) = NULL 43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Semaphore_Close(p) HandlePtr_Close(p) 44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define Semaphore_Wait(p) Handle_WaitObject(*(p)) 45baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); 46baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); 47baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes Semaphore_Release1(CSemaphore *p); 48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 49baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef CRITICAL_SECTION CCriticalSection; 50baa3858d3f5d128a5c8466b700098109edcad5f2repo syncWRes CriticalSection_Init(CCriticalSection *p); 51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define CriticalSection_Delete(p) DeleteCriticalSection(p) 52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define CriticalSection_Enter(p) EnterCriticalSection(p) 53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define CriticalSection_Leave(p) LeaveCriticalSection(p) 54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef __cplusplus 56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 60