mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 14:24:35 +01:00
trunk/branch integration: ScoppedRWLock
This commit is contained in:
parent
190dfbfde4
commit
8b5b500c0a
@ -38,7 +38,13 @@
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "RWLock_WINCE.cpp"
|
||||
#else
|
||||
#include "RWLock_WIN32.cpp"
|
||||
#endif
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#include "RWLock_VX.cpp"
|
||||
#else
|
||||
#include "RWLock_POSIX.cpp"
|
||||
#endif
|
||||
|
@ -114,22 +114,22 @@ void RWLockImpl::readLockImpl()
|
||||
|
||||
bool RWLockImpl::tryReadLockImpl()
|
||||
{
|
||||
HANDLE h[2];
|
||||
h[0] = _mutex;
|
||||
h[1] = _readEvent;
|
||||
switch (WaitForMultipleObjects(2, h, TRUE, 1))
|
||||
for (;;)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
++_readers;
|
||||
ResetEvent(_writeEvent);
|
||||
ReleaseMutex(_mutex);
|
||||
poco_assert_dbg(_writers == 0);
|
||||
return true;
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
default:
|
||||
throw SystemException("cannot lock reader/writer lock");
|
||||
if (_writers != 0 || _writersWaiting != 0)
|
||||
return false;
|
||||
|
||||
DWORD result = tryReadLockOnce();
|
||||
switch (result)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
return true;
|
||||
case WAIT_TIMEOUT:
|
||||
continue; // try again
|
||||
default:
|
||||
throw SystemException("cannot lock reader/writer lock");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,4 +203,27 @@ void RWLockImpl::unlockImpl()
|
||||
}
|
||||
|
||||
|
||||
DWORD RWLockImpl::tryReadLockOnce()
|
||||
{
|
||||
HANDLE h[2];
|
||||
h[0] = _mutex;
|
||||
h[1] = _readEvent;
|
||||
DWORD result = WaitForMultipleObjects(2, h, TRUE, 1);
|
||||
switch (result)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
++_readers;
|
||||
ResetEvent(_writeEvent);
|
||||
ReleaseMutex(_mutex);
|
||||
poco_assert_dbg(_writers == 0);
|
||||
return result;
|
||||
case WAIT_TIMEOUT:
|
||||
return result;
|
||||
default:
|
||||
throw SystemException("cannot lock reader/writer lock");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
Loading…
x
Reference in New Issue
Block a user