mirror of https://github.com/tongzx/nt5src
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
684 B
37 lines
684 B
#pragma once
|
|
|
|
class CCriticalSection
|
|
{
|
|
public:
|
|
CCriticalSection(CRITICAL_SECTION *pcs)
|
|
: _pcs(pcs)
|
|
{
|
|
// ASSERT(pcs);
|
|
}
|
|
|
|
HRESULT Lock()
|
|
{
|
|
HRESULT hr = S_OK;
|
|
|
|
__try {
|
|
::EnterCriticalSection(_pcs);
|
|
}
|
|
__except (EXCEPTION_EXECUTE_HANDLER) {
|
|
hr = E_OUTOFMEMORY;
|
|
}
|
|
|
|
return hr;
|
|
}
|
|
|
|
HRESULT Unlock()
|
|
{
|
|
::LeaveCriticalSection(_pcs);
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
private:
|
|
CRITICAL_SECTION *_pcs;
|
|
};
|
|
|
|
|