Merge branch 'issue_532' into issue_532-3 with edits

This commit is contained in:
martin-osborne
2014-10-30 11:10:39 +00:00
36 changed files with 499 additions and 67 deletions

View File

@@ -45,16 +45,13 @@ class Foundation_API Mutex: private MutexImpl
/// A Mutex (mutual exclusion) is a synchronization
/// mechanism used to control access to a shared resource
/// in a concurrent (multithreaded) scenario.
/// Mutexes are recursive, that is, the same mutex can be
/// locked multiple times by the same thread (but, of course,
/// not by other threads).
/// Using the ScopedLock class is the preferred way to automatically
/// lock and unlock a mutex.
{
public:
typedef Poco::ScopedLock<Mutex> ScopedLock;
Mutex();
explicit Mutex(bool recursive = true);
/// creates the Mutex.
~Mutex();

View File

@@ -32,8 +32,7 @@ namespace Poco {
class Foundation_API MutexImpl
{
protected:
MutexImpl();
MutexImpl(bool fast);
MutexImpl(bool recursive);
~MutexImpl();
void lockImpl();
bool tryLockImpl();

View File

@@ -32,8 +32,7 @@ namespace Poco {
class Foundation_API MutexImpl
{
protected:
MutexImpl();
MutexImpl(bool fast);
MutexImpl(bool recursive);
~MutexImpl();
void lockImpl();
bool tryLockImpl();

View File

@@ -31,25 +31,46 @@ namespace Poco {
class Foundation_API MutexImpl
{
protected:
MutexImpl();
MutexImpl(bool recursive);
~MutexImpl();
void lockImpl();
bool tryLockImpl();
bool tryLockImpl(long milliseconds);
void unlockImpl();
private:
CRITICAL_SECTION _cs;
int _lockCount;
const bool _recursive;
};
class Foundation_API FastMutexImpl
{
protected:
FastMutexImpl();
~FastMutexImpl();
void lockImpl();
bool tryLockImpl();
bool tryLockImpl(long milliseconds);
void unlockImpl();
private:
CRITICAL_SECTION _cs;
};
typedef MutexImpl FastMutexImpl;
//
// inlines
//
inline void MutexImpl::lockImpl()
inline void MutexImpl::unlockImpl()
{
--_lockCount;
LeaveCriticalSection(&_cs);
}
inline void FastMutexImpl::lockImpl()
{
try
{
@@ -62,7 +83,7 @@ inline void MutexImpl::lockImpl()
}
inline bool MutexImpl::tryLockImpl()
inline bool FastMutexImpl::tryLockImpl()
{
try
{
@@ -75,7 +96,7 @@ inline bool MutexImpl::tryLockImpl()
}
inline void MutexImpl::unlockImpl()
inline void FastMutexImpl::unlockImpl()
{
LeaveCriticalSection(&_cs);
}

View File

@@ -31,21 +31,35 @@ namespace Poco {
class Foundation_API MutexImpl
{
protected:
MutexImpl();
MutexImpl(bool recursive);
~MutexImpl();
void lockImpl();
bool tryLockImpl();
bool tryLockImpl(long milliseconds);
void unlockImpl();
private:
HANDLE _mutex;
int _lockCount;
const bool _recursive;
};
class Foundation_API FastMutexImpl
{
protected:
FastMutexImpl();
~FastMutexImpl();
void lockImpl();
bool tryLockImpl();
bool tryLockImpl(long milliseconds);
void unlockImpl();
private:
HANDLE _mutex;
};
typedef MutexImpl FastMutexImpl;
} // namespace Poco