CriticalSection.h
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:1k
源码类别:

P2P编程

开发平台:

Visual C++

  1. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  2. #pragma once
  3. #endif
  4. #ifndef _CRITICAL_SECTION_INCLUDED__
  5. #define _CRITICAL_SECTION_INCLUDED__
  6. class CriticalSection 
  7. {
  8.    public :
  9.    
  10.       class Owner
  11.       {
  12.          public:
  13.             explicit Owner(
  14.                CriticalSection &crit);
  15.             ~Owner();
  16.       
  17.          private :
  18.             CriticalSection &m_crit;
  19.             // No copies do not implement
  20.             Owner(const Owner &rhs);
  21.             Owner &operator=(const Owner &rhs);
  22.       };
  23.       CriticalSection();
  24.       
  25.       ~CriticalSection();
  26. #if(_WIN32_WINNT >= 0x0400)
  27.       bool TryEnter();
  28. #endif
  29.       void Enter();
  30.       void Leave();
  31.    private :
  32.       CRITICAL_SECTION m_crit;
  33.       // No copies do not implement
  34.       CriticalSection(const CriticalSection &rhs);
  35.       CriticalSection &operator=(const CriticalSection &rhs);
  36. };
  37. #endif //_CRITICAL_SECTION_INCLUDED__