mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 21:23:03 +01:00
Let's separate Mutex and Spinlock.
This commit is contained in:
parent
011bc0b9b2
commit
b4304d3998
@ -1176,7 +1176,7 @@ void MemoryPool::deletePool(MemoryPool* pool)
|
||||
pool->decrement_mapping(pool->mapped_memory);
|
||||
|
||||
// Free mutex
|
||||
pool->lock.~Mutex();
|
||||
pool->lock.~Spinlock();
|
||||
|
||||
// Order of deallocation is of significance because
|
||||
// we delete our pool in process
|
||||
|
@ -225,7 +225,7 @@ private:
|
||||
// accounted locally, i.e. redirect_amount and parent_redirected linked list
|
||||
// are synchronized with parent pool mutex only. All other pool members are
|
||||
// synchronized with this mutex.
|
||||
Mutex lock;
|
||||
Spinlock lock;
|
||||
|
||||
// Current usage counters for pool. Used to move pool to different statistics group
|
||||
AtomicCounter used_memory;
|
||||
|
@ -36,10 +36,9 @@ namespace Firebird {
|
||||
#define INIT_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(0))
|
||||
|
||||
tSetCriticalSectionSpinCount*
|
||||
Mutex::SetCriticalSectionSpinCount = INIT_SPIN_COUNT;
|
||||
Spinlock::SetCriticalSectionSpinCount = INIT_SPIN_COUNT;
|
||||
|
||||
Mutex::Mutex() {
|
||||
InitializeCriticalSection(&spinlock);
|
||||
Spinlock::Spinlock() {
|
||||
if (SetCriticalSectionSpinCount == MISS_SPIN_COUNT)
|
||||
return;
|
||||
if (SetCriticalSectionSpinCount == INIT_SPIN_COUNT) {
|
||||
|
@ -51,29 +51,39 @@ namespace Firebird {
|
||||
#ifdef MULTI_THREAD
|
||||
#ifdef WIN_NT
|
||||
|
||||
// Process-local spinlock. Used to manage memory heaps in threaded environment.
|
||||
// Generic process-local mutex and spinlock. The latter
|
||||
// is used to manage memory heaps in a threaded environment.
|
||||
|
||||
// Windows version of the class
|
||||
|
||||
class Mutex {
|
||||
protected:
|
||||
CRITICAL_SECTION spinlock;
|
||||
public:
|
||||
Mutex() {
|
||||
InitializeCriticalSection(&spinlock);
|
||||
}
|
||||
virtual ~Mutex() {
|
||||
DeleteCriticalSection(&spinlock);
|
||||
}
|
||||
virtual void enter() {
|
||||
EnterCriticalSection(&spinlock);
|
||||
}
|
||||
virtual void leave() {
|
||||
LeaveCriticalSection(&spinlock);
|
||||
}
|
||||
};
|
||||
|
||||
typedef WINBASEAPI DWORD WINAPI tSetCriticalSectionSpinCount (
|
||||
LPCRITICAL_SECTION lpCriticalSection,
|
||||
DWORD dwSpinCount
|
||||
);
|
||||
|
||||
class Mutex {
|
||||
class Spinlock : public Mutex {
|
||||
private:
|
||||
CRITICAL_SECTION spinlock;
|
||||
static tSetCriticalSectionSpinCount* SetCriticalSectionSpinCount;
|
||||
public:
|
||||
Mutex();
|
||||
~Mutex() {
|
||||
DeleteCriticalSection(&spinlock);
|
||||
}
|
||||
void enter() {
|
||||
EnterCriticalSection(&spinlock);
|
||||
}
|
||||
void leave() {
|
||||
LeaveCriticalSection(&spinlock);
|
||||
}
|
||||
Spinlock();
|
||||
};
|
||||
|
||||
#else //WIN_NT
|
||||
@ -102,6 +112,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef Mutex Spinlock;
|
||||
|
||||
#else //SOLARIS_MT
|
||||
|
||||
// Pthreads version of the class
|
||||
@ -127,6 +139,28 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class Spinlock {
|
||||
private:
|
||||
pthread_spinlock_t spinlock;
|
||||
public:
|
||||
Spinlock() {
|
||||
if (pthread_spin_init(&spinlock, false))
|
||||
system_call_failed::raise("pthread_spin_init");
|
||||
}
|
||||
~Spinlock() {
|
||||
if (pthread_spin_destroy(&spinlock))
|
||||
system_call_failed::raise("pthread_spin_destroy");
|
||||
}
|
||||
void enter() {
|
||||
if (pthread_spin_lock(&spinlock))
|
||||
system_call_failed::raise("pthread_spin_lock");
|
||||
}
|
||||
void leave() {
|
||||
if (pthread_spin_unlock(&spinlock))
|
||||
system_call_failed::raise("pthread_spin_unlock");
|
||||
}
|
||||
};
|
||||
|
||||
#endif //SOLARIS_MT
|
||||
|
||||
#endif //WIN_NT
|
||||
@ -146,6 +180,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef Mutex Spinlock;
|
||||
|
||||
#endif //MULTI_THREAD
|
||||
|
||||
// RAII holder of mutex lock
|
||||
|
Loading…
Reference in New Issue
Block a user