#pragma once

#include <boost/noncopyable.hpp>
#include <boost/thread/locks.hpp>

class CriticalSection : boost::noncopyable
{
  CRITICAL_SECTION m_sec;
public:
  typedef boost::unique_lock<CriticalSection> scoped_lock;

  CriticalSection()
  {
    InitializeCriticalSection(&m_sec);
  }
  ~CriticalSection()
  {
    DeleteCriticalSection(&m_sec);
  }

  // Lockable concept
  void lock()
  {
    EnterCriticalSection(&m_sec);
  }
  bool try_lock()
  {
    return TryEnterCriticalSection(&m_sec) == TRUE;
  }
  void unlock()
  {
    LeaveCriticalSection(&m_sec);
  }
};