Threads.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Threads.h */
  2. #ifndef __7Z_THRESDS_H
  3. #define __7Z_THRESDS_H
  4. #include <windows.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 StdCall
  14. #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
  15. HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
  16. HRes Thread_Wait(CThread *thread);
  17. HRes 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. HRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
  27. HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
  28. HRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
  29. HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
  30. HRes Event_Set(CEvent *event);
  31. HRes Event_Reset(CEvent *event);
  32. HRes Event_Wait(CEvent *event);
  33. HRes Event_Close(CEvent *event);
  34. typedef struct _CSemaphore
  35. {
  36. HANDLE handle;
  37. } CSemaphore;
  38. #define Semaphore_Construct(p) (p)->handle = NULL
  39. HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
  40. HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
  41. HRes Semaphore_Release1(CSemaphore *p);
  42. HRes Semaphore_Wait(CSemaphore *p);
  43. HRes Semaphore_Close(CSemaphore *p);
  44. typedef CRITICAL_SECTION CCriticalSection;
  45. HRes 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