Source code of Windows XP (NT5)
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.

74 lines
2.4 KiB

  1. //#pragma title( "TSync.hpp - Common synchronization classes header file" )
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - TSync.hpp
  6. System - Common
  7. Author - Rich Denham
  8. Created - 1996-11-08
  9. Description - Common synchronization classes header file
  10. This includes TCriticalSection, and TNamedSemaphore
  11. Updates -
  12. ===============================================================================
  13. */
  14. #ifndef MCSINC_TSync_hpp
  15. #define MCSINC_TSync_hpp
  16. #ifndef _INC_TIME
  17. #include <time.h>
  18. #endif
  19. class TCriticalSection
  20. {
  21. CRITICAL_SECTION cs;
  22. public:
  23. TCriticalSection() { InitializeCriticalSection(&cs); }
  24. ~TCriticalSection() { DeleteCriticalSection(&cs); }
  25. void Enter() { EnterCriticalSection(&cs); }
  26. void Leave() { LeaveCriticalSection(&cs); }
  27. };
  28. class TSynchObject
  29. {
  30. public:
  31. HANDLE handle;
  32. TSynchObject()
  33. { handle = NULL; }
  34. ~TSynchObject()
  35. { Close(); }
  36. void Close()
  37. { if ( handle != NULL ) { CloseHandle( handle ); handle = NULL; } }
  38. DWORD WaitSingle(DWORD msec) const { return WaitForSingleObject(handle, msec); }
  39. DWORD WaitSingle() const { return WaitForSingleObject(handle, INFINITE); }
  40. HANDLE Handle() { return handle; }
  41. };
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // Named semaphores
  44. ///////////////////////////////////////////////////////////////////////////////
  45. class TSemaphoreNamed : public TSynchObject
  46. {
  47. public:
  48. TSemaphoreNamed() {};
  49. ~TSemaphoreNamed() {};
  50. DWORD Create( // ret-OS return code
  51. TCHAR const * sNameT ,// in -semaphore name
  52. DWORD nInitial ,// in -initial count
  53. DWORD nMaximum ,// in -maximum count
  54. BOOL * pbExisted=NULL // out-TRUE=previously existed
  55. );
  56. DWORD Open( // ret-OS return code
  57. TCHAR const * sNameT // in -semaphore name
  58. );
  59. DWORD Release( // ret-OS return code
  60. long nRelease=1 // in -number to release
  61. );
  62. };
  63. #endif // MCSINC_TSync_hpp
  64. // TSync.hpp - end of file