mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 02:18:04 +01:00
Replaced boolean with enum in c'tor.
Implemented in a similar style to FPEnvironment.
This commit is contained in:
@@ -49,9 +49,16 @@ class Foundation_API Mutex: private MutexImpl
|
||||
/// lock and unlock a mutex.
|
||||
{
|
||||
public:
|
||||
enum MutexType
|
||||
/// The type of a mutex.
|
||||
{
|
||||
MUTEX_RECURSIVE = MUTEX_RECURSIVE_IMPL, /// A recursive mutex
|
||||
MUTEX_NONRECURSIVE = MUTEX_NONRECURSIVE_IMPL, /// A non-recursive mutex
|
||||
};
|
||||
|
||||
typedef Poco::ScopedLock<Mutex> ScopedLock;
|
||||
|
||||
explicit Mutex(bool recursive = true);
|
||||
explicit Mutex(MutexType type = MUTEX_RECURSIVE);
|
||||
/// creates the Mutex.
|
||||
|
||||
~Mutex();
|
||||
|
||||
@@ -31,8 +31,15 @@ namespace Poco {
|
||||
|
||||
class Foundation_API MutexImpl
|
||||
{
|
||||
public:
|
||||
enum MutexTypeImpl
|
||||
{
|
||||
MUTEX_RECURSIVE_IMPL,
|
||||
MUTEX_NONRECURSIVE_IMPL,
|
||||
};
|
||||
|
||||
protected:
|
||||
MutexImpl(bool recursive);
|
||||
explicit MutexImpl(MutexTypeImpl type);
|
||||
~MutexImpl();
|
||||
void lockImpl();
|
||||
bool tryLockImpl();
|
||||
|
||||
@@ -31,8 +31,15 @@ namespace Poco {
|
||||
|
||||
class Foundation_API MutexImpl
|
||||
{
|
||||
public:
|
||||
enum MutexTypeImpl
|
||||
{
|
||||
MUTEX_RECURSIVE_IMPL,
|
||||
MUTEX_NONRECURSIVE_IMPL,
|
||||
};
|
||||
|
||||
protected:
|
||||
MutexImpl(bool recursive);
|
||||
explicit MutexImpl(MutexTypeImpl type);
|
||||
~MutexImpl();
|
||||
void lockImpl();
|
||||
bool tryLockImpl();
|
||||
|
||||
@@ -30,8 +30,15 @@ namespace Poco {
|
||||
|
||||
class Foundation_API MutexImpl
|
||||
{
|
||||
public:
|
||||
enum MutexTypeImpl
|
||||
{
|
||||
MUTEX_RECURSIVE_IMPL,
|
||||
MUTEX_NONRECURSIVE_IMPL,
|
||||
};
|
||||
|
||||
protected:
|
||||
MutexImpl(bool recursive);
|
||||
explicit MutexImpl(MutexTypeImpl type);
|
||||
~MutexImpl();
|
||||
void lockImpl();
|
||||
bool tryLockImpl();
|
||||
|
||||
@@ -30,8 +30,15 @@ namespace Poco {
|
||||
|
||||
class Foundation_API MutexImpl
|
||||
{
|
||||
public:
|
||||
enum MutexTypeImpl
|
||||
{
|
||||
MUTEX_RECURSIVE_IMPL,
|
||||
MUTEX_NONRECURSIVE_IMPL,
|
||||
};
|
||||
|
||||
protected:
|
||||
MutexImpl(bool recursive);
|
||||
explicit MutexImpl(MutexTypeImpl type);
|
||||
~MutexImpl();
|
||||
void lockImpl();
|
||||
bool tryLockImpl();
|
||||
|
||||
@@ -49,12 +49,12 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
{
|
||||
Poco::Mutex mtx(true);
|
||||
Poco::Mutex mtx(Poco::Mutex::MUTEX_RECURSIVE);
|
||||
Benchmark(mtx, "Mutex(true)");
|
||||
}
|
||||
|
||||
{
|
||||
Poco::Mutex mtx(false);
|
||||
Poco::Mutex mtx(Poco::Mutex::MUTEX_NONRECURSIVE);
|
||||
Benchmark(mtx, "Mutex(false)");
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Mutex::Mutex(bool recursive)
|
||||
: MutexImpl(recursive)
|
||||
Mutex::Mutex(MutexType type)
|
||||
: MutexImpl((MutexTypeImpl) type)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl(bool recursive)
|
||||
MutexImpl::MutexImpl(MutexTypeImpl type)
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
// This workaround is for VxWorks 5.x where
|
||||
@@ -50,9 +50,9 @@ MutexImpl::MutexImpl(bool recursive)
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
#if defined(PTHREAD_MUTEX_RECURSIVE_NP)
|
||||
pthread_mutexattr_settype_np(&attr, recursive ? PTHREAD_MUTEX_RECURSIVE_NP : PTHREAD_MUTEX_NORMAL_NP);
|
||||
pthread_mutexattr_settype_np(&attr, type == MUTEX_RECURSIVE_IMPL ? PTHREAD_MUTEX_RECURSIVE_NP : PTHREAD_MUTEX_NORMAL_NP);
|
||||
#elif !defined(POCO_VXWORKS)
|
||||
pthread_mutexattr_settype(&attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
|
||||
pthread_mutexattr_settype(&attr, type == MUTEX_RECURSIVE_IMPL ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
|
||||
#endif
|
||||
if (pthread_mutex_init(&_mutex, &attr))
|
||||
{
|
||||
|
||||
@@ -21,15 +21,16 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl(bool recursive)
|
||||
MutexImpl::MutexImpl(MutexTypeImpl type)
|
||||
{
|
||||
if (recursive)
|
||||
switch (type)
|
||||
{
|
||||
case MUTEX_RECURSIVE_IMPL:
|
||||
_sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
case MUTEX_NONRECURSIVE_IMPL:
|
||||
_sem = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
|
||||
break;
|
||||
}
|
||||
if (_sem == 0)
|
||||
throw Poco::SystemException("cannot create mutex");
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl(bool recursive)
|
||||
MutexImpl::MutexImpl(MutexTypeImpl type)
|
||||
: _lockCount(0)
|
||||
, _recursive(recursive)
|
||||
, _recursive(type == MUTEX_RECURSIVE_IMPL)
|
||||
{
|
||||
// the fct has a boolean return value under WInnNt/2000/XP but not on Win98
|
||||
// the return only checks if the input address of &_cs was valid, so it is safe to omit it
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl(bool recursive)
|
||||
MutexImpl::MutexImpl(MutexTypeImpl type)
|
||||
: _lockCount(0)
|
||||
, _recursive(recursive)
|
||||
, _recursive(type == MUTEX_RECURSIVE_IMPL)
|
||||
{
|
||||
_mutex = CreateMutexW(NULL, FALSE, NULL);
|
||||
if (!_mutex) throw SystemException("cannot create mutex");
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace
|
||||
{
|
||||
try
|
||||
{
|
||||
Mutex mtx(false);
|
||||
Mutex mtx(Mutex::MUTEX_NONRECURSIVE);
|
||||
mtx.lock();
|
||||
mtx.lock();
|
||||
}
|
||||
@@ -74,7 +74,7 @@ MutexTest::~MutexTest()
|
||||
|
||||
void MutexTest::testMutexRecursion()
|
||||
{
|
||||
Mutex mtx(false);
|
||||
Mutex mtx(Mutex::MUTEX_NONRECURSIVE);
|
||||
mtx.lock();
|
||||
|
||||
bool success = mtx.tryLock();
|
||||
|
||||
Reference in New Issue
Block a user