📄 gspinlock.h
字号:
/* Copyright (C) 2006, Mike Gashler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. see http://www.gnu.org/copyleft/lesser.html*/#ifndef __GSPINLOCK_H__#define __GSPINLOCK_H__#ifndef WIN32#include <pthread.h>#endif// A spin-lock for synchronization purposesclass GSpinLock{protected:#ifdef _DEBUG const char* m_szUniqueStaticStringToIdentifyWhoLockedIt;#endif unsigned int m_dwLocked; // maintaned on all platform as posix mutexes don't have a way to get current state. // when not Win32 be aware that this value is shadowing the real mutex, and cannot be // depended on especially in a MP enviroment.#ifndef WIN32 pthread_mutex_t m_mutex;#endifpublic: GSpinLock(); virtual ~GSpinLock();#ifndef NO_TEST_CODE static void Test();#endif // !NO_TEST_CODE void Lock(const char* szUniqueStaticStringToIdentifyWhoLockedIt); void Unlock(); bool IsLocked() { return m_dwLocked != 0; } // see note above about m_dwLocked.};class GSpinLockHolder{protected: GSpinLock* m_pLock;public: GSpinLockHolder(GSpinLock* pLock, const char* szWhoHoldsTheLock) { m_pLock = pLock; pLock->Lock(szWhoHoldsTheLock); } ~GSpinLockHolder() { m_pLock->Unlock(); }};#endif // __GSPINLOCK_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -