#include "SimpleMutex.h" #include SimpleMutex::SimpleMutex() { hMutex = CreateMutex(NULL, FALSE, 0); assert(hMutex); } SimpleMutex::~SimpleMutex() { CloseHandle(hMutex); } void SimpleMutex::Lock(void) { #ifdef _DEBUG DWORD d = #endif WaitForSingleObject(hMutex, INFINITE); #ifdef _DEBUG assert(d==WAIT_OBJECT_0); #endif } void SimpleMutex::Unlock(void) { #ifdef _DEBUG BOOL b = #endif ReleaseMutex(hMutex); #ifdef _DEBUG if (b==0) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); // Process any inserts in lpMsgBuf. // ... // Display the string. MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); // Free the buffer. LocalFree( lpMsgBuf ); assert(1); } #endif }