Threads.h 2.0 KB

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