8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 19:23:03 +01:00

fixed posix SS - use recursive mutex to protect security DB access

This commit is contained in:
alexpeshkoff 2008-01-29 15:03:34 +00:00
parent 42db58c37f
commit 35520bc1f1
3 changed files with 20 additions and 15 deletions

View File

@ -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 <typename M>
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<Mutex> MutexLockGuard;
typedef LockGuard<RecursiveMutex> RecursiveMutexLockGuard;
} //namespace Firebird
#endif // CLASSES_LOCKS_H

View File

@ -90,6 +90,7 @@ private:
static const UCHAR TPB[4];
Firebird::Mutex mutex;
Firebird::RecursiveMutex counterMutex;
ISC_STATUS_ARRAY status;

View File

@ -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;
}