winlock.h
来自「hoard内存管理器」· C头文件 代码 · 共 96 行
H
96 行
/* -*- C++ -*- */#ifndef _WINLOCK_H_#define _WINLOCK_H_#if defined(_WIN32)#include <windows.h>/** * @class WinLockType * @brief Locking using Win32 mutexes. * * Note that this lock type detects whether we are running on a * multiprocessor. If not, then we do not use atomic operations. */#if 1namespace HL {class WinLockType {public: WinLockType (void) : mutex (0) {} ~WinLockType (void) { mutex = 0; } inline void lock (void) {#if 1 // We're on a multiprocessor - use atomic operations. while (InterlockedExchange ((long *) &mutex, 1) != 0) Sleep (0);#endif } inline void unlock (void) { mutex = 0; // InterlockedExchange (&mutex, 0); }private: unsigned int mutex; bool onMultiprocessor (void) { SYSTEM_INFO infoReturn[1]; GetSystemInfo (infoReturn); if (infoReturn->dwNumberOfProcessors == 1) { return FALSE; } else { return TRUE; } }};};#else#include <windows.h>class WinLockType {public: WinLockType (void) { InitializeCriticalSection(&mutex); } ~WinLockType (void) { DeleteCriticalSection(&mutex); } inline void lock (void) { EnterCriticalSection(&mutex); } inline void unlock (void) { LeaveCriticalSection(&mutex); }private: CRITICAL_SECTION mutex;};#endif#endif#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?