11 #if defined(_DEBUG) && defined( HAVE_STRUCTURED_EH ) 12 #define SYNCOBJ_DBG_SEH 1 15 return (xCode == STATUS_NO_MEMORY)
24 #define SYNCOBJ_DBG_SEH 0 31 memset( &
_cSec, 0,
sizeof(CRITICAL_SECTION) );
34 __try { InitializeCriticalSection( &
_cSec ); }
37 ACSTR xName = GetCritSecExcName( GetExceptionCode());
42 InitializeCriticalSection( &
_cSec );
48 memset( &
_cSec, 0,
sizeof(CRITICAL_SECTION) );
50 __try { InitializeCriticalSectionAndSpinCount( &
_cSec, SpinCount ); }
53 ACSTR xName = GetCritSecExcName( GetExceptionCode());
58 InitializeCriticalSectionAndSpinCount( &
_cSec, SpinCount );
64 DeleteCriticalSection( &
_cSec );
69 return SetCriticalSectionSpinCount( &
_cSec, SpinCount );
79 static DWORD __csectExFilter( IN PEXCEPTION_POINTERS pexPtr,
CSTR Where )
82 ACSTR xName = GetCritSecExcName( pexPtr->ExceptionRecord->ExceptionCode );
89 return EXCEPTION_CONTINUE_SEARCH;
91 #endif //SYNCOBJ_DBG_SEH 96 __try { EnterCriticalSection( &
_cSec ); }
97 __except( __csectExFilter( GetExceptionInformation(), (
CSTR)__FUNCTION__ ))
101 DWORD xCode = GetExceptionCode();
102 ACSTR xName = GetCritSecExcName( xCode );
107 EnterCriticalSection( &
_cSec );
118 LeaveCriticalSection( &
_cSec );
142 static bool __CheckWaitResult(
DWORD rc )
144 bool ok = (rc == WAIT_OBJECT_0);
149 if (!ok && (rc != WAIT_FAILED)) SetLastError( rc );
156 if (!ok) SetLastError( ERROR_INVALID_HANDLE );
160 ok = __CheckWaitResult( rc );
168 if (!ok) SetLastError( ERROR_INVALID_HANDLE );
171 DWORD rc = WaitForSingleObjectEx(
_hSync, msWait, Alertable );
172 ok = __CheckWaitResult( rc );
180 if (!ok) SetLastError( ERROR_INVALID_HANDLE );
183 DWORD rc = SignalObjectAndWait(
_hSync, hWaitFor, msWait, Alertable );
184 ok = __CheckWaitResult( rc );
191 HANDLE hWaitObj = NULL;
192 if (!
Initialized()) SetLastError( ERROR_INVALID_HANDLE );
195 RegisterWaitForSingleObject( &hWaitObj,
_hSync, Callback, Context, msWait, Flags );
207 HANDLE hTrg = NULL, hProc = GetCurrentProcess();
208 if (!
Initialized()) SetLastError( ERROR_INVALID_HANDLE );
211 Opt &= ~DUPLICATE_CLOSE_SOURCE;
212 DuplicateHandle( hProc,
_hSync, TargetProc, &hTrg, Access, Inherit, Opt );
222 _hSync = CreateEvent( SecAttr, Manual, Init, Name );
228 _hSync = OpenEvent( Access, Inherit, Name );
256 _hSync = CreateMutex( SecAttr, Own, Name );
262 _hSync = OpenMutex( Access, Inherit, Name );
280 _hSync = CreateSemaphore( SecAttr,
Count, MaxCount, Name );
286 _hSync = OpenSemaphore( Access, Inherit, Name );
296 if (OldCount) *OldCount = 0;
306 if (!
_hSync) SetLastError( ERROR_INVALID_HANDLE );
318 if (!
_hSync) SetLastError( ERROR_INVALID_HANDLE );
327 _hSync = CreateWaitableTimer( SecAttr, Manual, Name );
332 _hSync = OpenWaitableTimer( Access, Inherit, Name );
340 bool TWaitTimer::Set( FILETIME Due, LONG Period, PTIMERAPCROUTINE Action, PVOID Context,
bool Resume )
342 ULARGE_INTEGER due = { Due.dwLowDateTime, Due.dwHighDateTime };
343 return bool_cast( SetWaitableTimer(
_hSync, (LARGE_INTEGER*)&due, Period, Action, Context, Resume ));
350 due.QuadPart = (Due < 0) ? Due : -Due;
351 bool ok =
bool_cast( SetWaitableTimer(
_hSync, &due, Period, Action, Context, Resume ));
362 #undef SYNCOBJ_DBG_SEH
HANDLE CloseHandleEx(HANDLE H)
TSemaphore(LPSECURITY_ATTRIBUTES SecAttr, LONG Count, LONG MaxCount, CSTR Name=NULL)
bool UnregisterWait(HANDLE hWait)
bool WaitFor(HANDLE hObj, DWORD msWait)
bool Release(LONG Count, OPTOUT LPLONG OldCount=NULL)
bool WaitEx(DWORD msWait, bool Alertable)
void __cdecl DPrint(int Level, CSTR Fmt,...)
TWaitTimer(LPSECURITY_ATTRIBUTES SecAttr, bool Manual, CSTR Name=NULL)
HANDLE RegisterWait(WAITORTIMERCALLBACK Callback, PVOID Context, DWORD msWait, DWORD Flags)
bool Set(FILETIME Due, LONG Period, PTIMERAPCROUTINE Action, PVOID Context, bool Resume)
bool __forceinline bool_cast(BOOL B52)
Debug and error handling support.
TEvent(LPSECURITY_ATTRIBUTES SecAttr, bool Manual, bool Init, CSTR Name=NULL)
bool SignalAndWait(HANDLE hWaitFor, DWORD msWait, bool Alertable)
bool Pulse()
Note: Documented as unreliable. Included just for completeness.
ACSTR GetExceptionName(DWORD xCode)
HANDLE Duplicate(HANDLE TargetProc, bool Inherit, ACCESS_MASK Access=0, DWORD Opt=DUPLICATE_SAME_ACCESS)
DWORD SetSpinCount(DWORD SpinCount)
TMutex(LPSECURITY_ATTRIBUTES SecAttr, bool Own, CSTR Name=NULL)