-
Notifications
You must be signed in to change notification settings - Fork 4
/
ScopeLock.cpp
44 lines (36 loc) · 1.16 KB
/
ScopeLock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// **************************************************************************
#include <assert.h>
#include <windows.h>
#include "Max.h"
#include "ScopeLock.h"
//
// ScopeLock
//
// A class whose purpose is to provide an easy way to manage
// the acquisition and release of a CRITICAL_SECTION object
//
// The critical section is entered in the constructor and
// left in the destructor. This is useful for scope based
// synchronization. For example
//
// void f()
// {
// ScopeLock(&CSObject);
//
// // do some stuff
//
// } // critical section released on block exit.
//
// **************************************************************************
ScopeLock::ScopeLock(CRITICAL_SECTION* cs) : m_pCritSec(cs) {
assert(m_pCritSec);
EnterCriticalSection(m_pCritSec);
DebugPrint(_T("ScopeLock::EnterCriticalSection()\n"));
}
// **************************************************************************
ScopeLock::~ScopeLock() {
assert(m_pCritSec);
LeaveCriticalSection(m_pCritSec);
DebugPrint(_T("ScopeLock::LeaveCriticalSection()\n"));
}
// **************************************************************************