mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 22:29:47 +01:00
trunk/branch integration: ScoppedRWLock
This commit is contained in:
@@ -38,7 +38,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||||
|
#if defined(_WIN32_WCE)
|
||||||
|
#include "RWLock_WINCE.cpp"
|
||||||
|
#else
|
||||||
#include "RWLock_WIN32.cpp"
|
#include "RWLock_WIN32.cpp"
|
||||||
|
#endif
|
||||||
|
#elif defined(POCO_VXWORKS)
|
||||||
|
#include "RWLock_VX.cpp"
|
||||||
#else
|
#else
|
||||||
#include "RWLock_POSIX.cpp"
|
#include "RWLock_POSIX.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -114,22 +114,22 @@ void RWLockImpl::readLockImpl()
|
|||||||
|
|
||||||
bool RWLockImpl::tryReadLockImpl()
|
bool RWLockImpl::tryReadLockImpl()
|
||||||
{
|
{
|
||||||
HANDLE h[2];
|
for (;;)
|
||||||
h[0] = _mutex;
|
|
||||||
h[1] = _readEvent;
|
|
||||||
switch (WaitForMultipleObjects(2, h, TRUE, 1))
|
|
||||||
{
|
{
|
||||||
case WAIT_OBJECT_0:
|
if (_writers != 0 || _writersWaiting != 0)
|
||||||
case WAIT_OBJECT_0 + 1:
|
return false;
|
||||||
++_readers;
|
|
||||||
ResetEvent(_writeEvent);
|
DWORD result = tryReadLockOnce();
|
||||||
ReleaseMutex(_mutex);
|
switch (result)
|
||||||
poco_assert_dbg(_writers == 0);
|
{
|
||||||
return true;
|
case WAIT_OBJECT_0:
|
||||||
case WAIT_TIMEOUT:
|
case WAIT_OBJECT_0 + 1:
|
||||||
return false;
|
return true;
|
||||||
default:
|
case WAIT_TIMEOUT:
|
||||||
throw SystemException("cannot lock reader/writer lock");
|
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
|
} // namespace Poco
|
||||||
|
|||||||
Reference in New Issue
Block a user