Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

  1. /* Threads.h -- multithreading library
  2. 2013-11-12 : 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_Close(p) HandlePtr_Close(p)
  44. #define Semaphore_Wait(p) Handle_WaitObject(*(p))
  45. WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
  46. WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
  47. WRes Semaphore_Release1(CSemaphore *p);
  48. typedef CRITICAL_SECTION CCriticalSection;
  49. WRes CriticalSection_Init(CCriticalSection *p);
  50. #define CriticalSection_Delete(p) DeleteCriticalSection(p)
  51. #define CriticalSection_Enter(p) EnterCriticalSection(p)
  52. #define CriticalSection_Leave(p) LeaveCriticalSection(p)
  53. EXTERN_C_END
  54. #endif