mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 01:23:03 +01:00
Explicit init for mutexes - thanks to Claudio
This commit is contained in:
parent
09e5f151e6
commit
cbed6dbcf2
@ -91,6 +91,7 @@ namespace
|
||||
return;
|
||||
}
|
||||
|
||||
Firebird::Mutex::initMutexes();
|
||||
Firebird::MemoryPool::init();
|
||||
Firebird::StaticMutex::create();
|
||||
|
||||
|
@ -73,12 +73,12 @@ void Spinlock::init()
|
||||
|
||||
#else //posix mutex
|
||||
|
||||
bool Mutex::attrDone = false;
|
||||
pthread_mutexattr_t Mutex::attr;
|
||||
|
||||
void Mutex::initAttr()
|
||||
void Mutex::initMutexes()
|
||||
{
|
||||
// Throw exceptions on errors, but they will not be processed in first mutex constructor...
|
||||
// Throw exceptions on errors, but they will not be processed in init
|
||||
// (first constructor). Better logging facilities are required here.
|
||||
int rc = pthread_mutexattr_init(&attr);
|
||||
if (rc < 0)
|
||||
system_call_failed::raise("pthread_mutexattr_init", rc);
|
||||
@ -86,8 +86,6 @@ void Mutex::initAttr()
|
||||
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
if (rc < 0)
|
||||
system_call_failed::raise("pthread_mutexattr_settype", rc);
|
||||
|
||||
attrDone = true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -60,6 +60,7 @@ class Mutex
|
||||
{
|
||||
protected:
|
||||
CRITICAL_SECTION spinlock;
|
||||
|
||||
public:
|
||||
Mutex() {
|
||||
InitializeCriticalSection(&spinlock);
|
||||
@ -76,6 +77,9 @@ public:
|
||||
void leave() {
|
||||
LeaveCriticalSection(&spinlock);
|
||||
}
|
||||
|
||||
public:
|
||||
static void initMutexes() { }
|
||||
};
|
||||
|
||||
typedef WINBASEAPI DWORD WINAPI tSetCriticalSectionSpinCount (
|
||||
@ -112,6 +116,7 @@ class Mutex
|
||||
{
|
||||
private:
|
||||
mutex_t mlock;
|
||||
|
||||
public:
|
||||
Mutex() {
|
||||
if (mutex_init(&mlock, USYNC_PROCESS, NULL))
|
||||
@ -133,6 +138,9 @@ public:
|
||||
if (mutex_unlock(&mlock))
|
||||
system_call_failed::raise("mutex_unlock");
|
||||
}
|
||||
|
||||
public:
|
||||
static void initMutexes() { }
|
||||
};
|
||||
|
||||
typedef Mutex Spinlock;
|
||||
@ -144,18 +152,15 @@ class Mutex
|
||||
{
|
||||
private:
|
||||
pthread_mutex_t mlock;
|
||||
static bool attrDone;
|
||||
static pthread_mutexattr_t attr;
|
||||
static void initAttr();
|
||||
|
||||
private:
|
||||
void init() {
|
||||
if (! attrDone)
|
||||
initAttr();
|
||||
int rc = pthread_mutex_init(&mlock, &attr);
|
||||
if (rc < 0)
|
||||
system_call_failed::raise("pthread_mutex_init");
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
Mutex() { init(); }
|
||||
explicit Mutex(MemoryPool&) { init(); }
|
||||
@ -174,6 +179,9 @@ public:
|
||||
if (rc < 0)
|
||||
system_call_failed::raise("pthread_mutex_unlock");
|
||||
}
|
||||
|
||||
public:
|
||||
static void initMutexes();
|
||||
};
|
||||
|
||||
#ifndef DARWIN
|
||||
|
Loading…
Reference in New Issue
Block a user