From 35520bc1f1f611f2621d9da7ff6541a7f23d1b6e Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Tue, 29 Jan 2008 15:03:34 +0000 Subject: [PATCH] fixed posix SS - use recursive mutex to protect security DB access --- src/common/classes/locks.h | 30 +++++++++++++++++------------- src/jrd/jrd_pwd.h | 1 + src/jrd/pwd.cpp | 4 ++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/common/classes/locks.h b/src/common/classes/locks.h index c553f50c19..bd07f89558 100644 --- a/src/common/classes/locks.h +++ b/src/common/classes/locks.h @@ -197,19 +197,6 @@ public: #endif //WIN_NT -// RAII holder of mutex lock -class MutexLockGuard -{ -public: - explicit MutexLockGuard(Mutex &alock) - : lock(&alock) { lock->enter(); } - ~MutexLockGuard() { lock->leave(); } -private: - // Forbid copy constructor - MutexLockGuard(const MutexLockGuard& source); - Mutex *lock; -}; - // Recursive mutex class RecursiveMutex { @@ -231,6 +218,23 @@ public: int leave(); }; +// RAII holder +template +class LockGuard +{ +public: + explicit LockGuard(M &alock) + : lock(&alock) { lock->enter(); } + ~LockGuard() { lock->leave(); } +private: + // Forbid copy constructor + LockGuard(const LockGuard& source); + M *lock; +}; + +typedef LockGuard MutexLockGuard; +typedef LockGuard RecursiveMutexLockGuard; + } //namespace Firebird #endif // CLASSES_LOCKS_H diff --git a/src/jrd/jrd_pwd.h b/src/jrd/jrd_pwd.h index 0579956891..9fde98b530 100644 --- a/src/jrd/jrd_pwd.h +++ b/src/jrd/jrd_pwd.h @@ -90,6 +90,7 @@ private: static const UCHAR TPB[4]; Firebird::Mutex mutex; + Firebird::RecursiveMutex counterMutex; ISC_STATUS_ARRAY status; diff --git a/src/jrd/pwd.cpp b/src/jrd/pwd.cpp index 56666d01ce..1fe4be75f7 100644 --- a/src/jrd/pwd.cpp +++ b/src/jrd/pwd.cpp @@ -235,7 +235,7 @@ namespace { void SecurityDatabase::fini() { - Firebird::MutexLockGuard guard(mutex); + Firebird::RecursiveMutexLockGuard guard(counterMutex); counter -= (is_cached) ? 1 : 0; #ifndef EMBEDDED if (counter == 1 && lookup_db) @@ -247,7 +247,7 @@ void SecurityDatabase::fini() void SecurityDatabase::init() { - Firebird::MutexLockGuard guard(mutex); + Firebird::RecursiveMutexLockGuard guard(counterMutex); counter += (is_cached) ? 1 : 0; }