GENRS_SyncObject.h
上传用户:hygd004
上传日期:2022-02-04
资源大小:1841k
文件大小:3k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // -------------------------  FILE HEADER  --------------------------------
  2. //
  3. // CM Ident:  $Header: 
  4. //
  5. // COPYRIGHT  AmBow Inc., SuZhou. 2002 All Rights Reserved
  6. //
  7. // File:      GENRS_SyncObject.h
  8. //
  9. // Project:   AmBow's Reusability Project
  10. //
  11. // Purpose:   Inline header file for the class GENRS_SyncObject
  12. //
  13. // ------------------------------------------------------------------------
  14. #ifndef _GENRS_SyncObject_H_
  15. #define _GENRS_SyncObject_H_
  16. // --------------------------  System Includes  ---------------------------
  17. // --------------------------  AmBow  Includes  ---------------------------
  18. // -----------------------------  Constants  ------------------------------
  19. // -------------------------  Forward References  -------------------------
  20. // --------------------------  Type Definitions  --------------------------
  21. // ------------------------------------------------------  GENRS_SyncObject
  22. // Description:
  23. //  Synchronization Object class.this class used to lock some variables,
  24. //  they will be used in multiple thread.
  25. //  when a thread want access these variables ,call the lock method;
  26. //  and when end accessing these variables,call the unlock method.
  27. // ------------------------------------------------------------------------    
  28. class GENRS_SyncObject
  29. {
  30. // ------------------------------------------------------------------------
  31. // Public Methods
  32. // ------------------------------------------------------------------------
  33. //make SyncObject can not be called Copy-Constuctor and Assign-Constuctor
  34.     GENRS_SyncObject(const GENRS_SyncObject & rSynObj);
  35.     GENRS_SyncObject & operator=(const GENRS_SyncObject & rSynObj);
  36. public:
  37.     GENRS_SyncObject()
  38.     {
  39. #ifdef _WINDOWS_
  40.         InitializeCriticalSection(&m_KernelObject);
  41. #endif
  42.     }
  43.     ~GENRS_SyncObject()
  44.     {
  45. #ifdef _WINDOWS_
  46.         DeleteCriticalSection(&m_KernelObject);
  47. #endif
  48.     }
  49. // ------------------------------------------------------------------- Lock
  50. // Description:
  51. //  before accessing the data in vary thread,call this function to lock 
  52. //    the sync object.
  53. //   Note:on vary platform ,implementation may be diff.
  54. // ------------------------------------------------------------------------
  55.     void Lock()
  56.     {
  57. #ifdef _WINDOWS_
  58.         EnterCriticalSection(&m_KernelObject);
  59. #endif
  60.     }
  61. // ----------------------------------------------------------------- Unlock
  62. // Description:
  63. //  When accessing finished the data in vary thread,call this function to 
  64. // unlock the sync object.
  65. //   Note:on vary platform ,implementation may be diff.
  66. // ------------------------------------------------------------------------
  67.     void Unlock()
  68.     {
  69. #ifdef _WINDOWS_
  70.         LeaveCriticalSection(&m_KernelObject);
  71. #endif
  72.     }
  73. // ------------------------------------------------------------------------
  74. // Private Methods & Data Members
  75. // ------------------------------------------------------------------------
  76. private:        
  77. // --------------------------  Private Data Members  ----------------------
  78. private:
  79. // --------------------------------------------------------- m_KernelObject
  80. // Description:
  81. //   this object manage the kernel sync object.define same name with vary 
  82. //  platfroms.
  83. // ------------------------------------------------------------------------
  84. #ifdef _WINDOWS_
  85.     CRITICAL_SECTION m_KernelObject;
  86. #elif defined (_UNIX)
  87.     
  88. #endif
  89. };
  90. #endif