thread/Id: new class replacing GThread pointers

Remove a GLib dependencies from class EventLoop and DatabaseLock.
This commit is contained in:
Max Kellermann
2013-08-10 09:00:04 +02:00
parent 018f4155eb
commit d23c907a94
6 changed files with 117 additions and 15 deletions

View File

@@ -30,14 +30,15 @@
#include "thread/Mutex.hxx"
#include "gcc.h"
#include <glib.h>
#include <assert.h>
extern Mutex db_mutex;
#ifndef NDEBUG
extern GThread *db_mutex_holder;
#include "thread/Id.hxx"
extern ThreadId db_mutex_holder;
/**
* Does the current thread hold the database lock?
@@ -46,7 +47,7 @@ gcc_pure
static inline bool
holding_db_lock(void)
{
return db_mutex_holder == g_thread_self();
return db_mutex_holder.IsInside();
}
#endif
@@ -62,9 +63,9 @@ db_lock(void)
db_mutex.lock();
assert(db_mutex_holder == NULL);
assert(db_mutex_holder.IsNull());
#ifndef NDEBUG
db_mutex_holder = g_thread_self();
db_mutex_holder = ThreadId::GetCurrent();
#endif
}
@@ -76,7 +77,7 @@ db_unlock(void)
{
assert(holding_db_lock());
#ifndef NDEBUG
db_mutex_holder = NULL;
db_mutex_holder = ThreadId::Null();
#endif
db_mutex.unlock();