Threads.h 2.1 KB

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