ReadWriteMutex.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // "$Id$"
  3. //
  4. // Copyright (c)1992-2011, ZheJiang Dahua Technology Stock CO.LTD.
  5. // All Rights Reserved.
  6. //
  7. // Description:
  8. // Revisions: Year-Month-Day SVN-Author Modification
  9. //
  10. #ifndef __INFRA3_RW_MUTEX_H__
  11. #define __INFRA3_RW_MUTEX_H__
  12. #include "Defs.h"
  13. namespace Dahua{
  14. namespace Infra{
  15. struct RWMutexInternal;
  16. /// \class CMutex
  17. /// \brief 多平台互斥量类
  18. class INFRA_API CReadWriteMutex
  19. {
  20. CReadWriteMutex(CReadWriteMutex const&);
  21. CReadWriteMutex& operator=(CReadWriteMutex const&);
  22. /// 设置读写锁优先级枚举类型RWPriority
  23. /// \param priorityDefault 设置默认优先级,linux下读锁优先,WIN32下保持原先状态暂未实现。
  24. /// \param priorityWrite 设置写锁优先级,linux下写锁优先,WIN32下保持原先状态暂未实现。
  25. public:
  26. enum RWPriority
  27. {
  28. priorityDefault = 0,
  29. priorityWrite = 1,
  30. };
  31. public:
  32. /// 构造函数,会创建系统互斥量
  33. CReadWriteMutex();
  34. /// 构造函数,会创建系统互斥量,并传入读写锁优先级设置参数
  35. /// \ param rwpriority 读写锁优先级参数,枚举类型
  36. CReadWriteMutex(RWPriority rwpriority);
  37. /// 析构函数,会销毁系统互斥量
  38. ~CReadWriteMutex();
  39. /// 进入临界区。
  40. /// \return 操作是否成功
  41. bool enterReading();
  42. /// 进入临界区。
  43. /// \return 操作是否成功
  44. bool enterWriting();
  45. /// 离开临界区。
  46. /// \return 操作是否成功
  47. bool leave();
  48. private:
  49. RWMutexInternal* m_internal;
  50. };
  51. } // namespace Infra
  52. } // namespace Dahua
  53. #endif //__INFRA_RW_MUTEX_H__
  54. //
  55. // End of "$Id: Mutex.h 16503 2010-11-26 02:23:15Z wang_haifeng $"
  56. //