12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #include "stdafx.h"
- #include "Lock.h"
- CLock::CLock()
- {
- InitializeCriticalSection(&cs);
- }
- CLock::~CLock()
- {
- DeleteCriticalSection(&cs);
- }
- /************************************************************************/
- /*
- 函数:lock
- 描述:锁
- 参数:
- 返回:
- */
- /************************************************************************/
- void CLock::lock()
- {
- EnterCriticalSection(&cs);
- }
- /************************************************************************/
- /*
- 函数:unlock
- 描述:解锁
- 参数:
- 返回:
- */
- /************************************************************************/
- void CLock::unlock()
- {
- LeaveCriticalSection(&cs);
- }
- CAutoLock::CAutoLock(CLock* plock)
- {
- if(plock == NULL)
- return;
- m_plock = plock;
- m_plock->lock();
- }
- CAutoLock::~CAutoLock()
- {
- m_plock->unlock();
- m_plock = NULL;
- }
|