MWCapture SDK Linux  3.3.1.LAST_SVN_COMMIT_NUM
LockUtils.h
1 
2 #pragma once
3 
4 
5 class CMWLock
6 {
7 public:
8  CMWLock() {
9  InitializeCriticalSection(&m_cs);
10  }
11 
12  virtual ~CMWLock() {
13  DeleteCriticalSection(&m_cs);
14  }
15 
16 public:
17  void Lock() {
18  EnterCriticalSection(&m_cs);
19  }
20 
21  void Unlock() {
22  LeaveCriticalSection(&m_cs);
23  }
24 
25  BOOL TryLock() {
26  return TryEnterCriticalSection(&m_cs);
27  }
28 protected:
29  CRITICAL_SECTION m_cs;
30 };
31 
33 {
34 public:
35  CMWAutoLock(CMWLock & section) : m_section(section)
36  {
37  m_section.Lock();
38  }
39 
40  virtual ~CMWAutoLock() {
41  m_section.Unlock();
42  }
43 
44 protected:
45  CMWLock& m_section;
46 };
47 
49 {
50 public:
51  CMWAutoUnLock(CMWLock & section) : m_section(section)
52  {
53  m_section.Unlock();
54  }
55 
56  virtual ~CMWAutoUnLock() {
57  m_section.Lock();
58  }
59 
60 protected:
61  CMWLock& m_section;
62 };
Definition: LockUtils.h:5
Definition: LockUtils.h:48
Definition: LockUtils.h:32