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.
112 lines
2.4 KiB
112 lines
2.4 KiB
|
|
//+-------------------------------------------------------------------------
|
|
//
|
|
// Microsoft Windows
|
|
// Copyright (C) Microsoft Corporation, 1997.
|
|
//
|
|
// File: critsect.cpp
|
|
//
|
|
// Contents: critical section helper class
|
|
//
|
|
// Classes: CCriticalSection
|
|
// CLockHandler
|
|
// CLock
|
|
//
|
|
//
|
|
// Notes:
|
|
//
|
|
// History: 13-Nov-97 rogerg Created.
|
|
//
|
|
//--------------------------------------------------------------------------
|
|
|
|
#include "lib.h"
|
|
|
|
//+---------------------------------------------------------------------------
|
|
//
|
|
// Member: CLockHandler::CLockHandler, public
|
|
//
|
|
// Synopsis: Constructor
|
|
//
|
|
// Arguments:
|
|
//
|
|
// Returns:
|
|
//
|
|
// Modifies:
|
|
//
|
|
// History: 05-Nov-97 rogerg Created.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
CLockHandler::CLockHandler()
|
|
{
|
|
m_dwLockThreadId = 0;
|
|
InitializeCriticalSection(&m_CriticalSection);
|
|
}
|
|
|
|
//+---------------------------------------------------------------------------
|
|
//
|
|
// Member: CLockHandler::~CLockHandler, public
|
|
//
|
|
// Synopsis: Destructor
|
|
//
|
|
// Arguments:
|
|
//
|
|
// Returns:
|
|
//
|
|
// Modifies:
|
|
//
|
|
// History: 05-Nov-97 rogerg Created.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
CLockHandler::~CLockHandler()
|
|
{
|
|
Assert (0 == m_dwLockThreadId);
|
|
DeleteCriticalSection(&m_CriticalSection);
|
|
}
|
|
|
|
//+---------------------------------------------------------------------------
|
|
//
|
|
// Member: CLockHandler::Lock, public
|
|
//
|
|
// Synopsis: Adds a lock to the specified class
|
|
//
|
|
// Arguments:
|
|
//
|
|
// Returns:
|
|
//
|
|
// Modifies:
|
|
//
|
|
// History: 05-Nov-97 rogerg Created.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
void CLockHandler::Lock(DWORD dwThreadId)
|
|
{
|
|
EnterCriticalSection(&m_CriticalSection);
|
|
|
|
m_dwLockThreadId = dwThreadId;
|
|
}
|
|
|
|
//+---------------------------------------------------------------------------
|
|
//
|
|
// Member: CLockHandler::UnLock, public
|
|
//
|
|
// Synopsis: Removes a lock to the specified class
|
|
//
|
|
// Arguments:
|
|
//
|
|
// Returns:
|
|
//
|
|
// Modifies:
|
|
//
|
|
// History: 05-Nov-97 rogerg Created.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
void CLockHandler::UnLock()
|
|
{
|
|
m_dwLockThreadId = 0;
|
|
LeaveCriticalSection(&m_CriticalSection);
|
|
}
|
|
|