diff options
author | Max Kellermann <max@duempel.org> | 2012-02-02 17:52:11 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-02-02 17:59:51 +0100 |
commit | 837bd79b20d4b9b8525a42999a9d1911f8980aa4 (patch) | |
tree | 6fd905d907929d00296a92b4784ed2cd561523b4 /src | |
parent | 3edd4a24afe295eaf4b811a265318338b6690af2 (diff) | |
download | mpd-837bd79b20d4b9b8525a42999a9d1911f8980aa4.tar.gz mpd-837bd79b20d4b9b8525a42999a9d1911f8980aa4.tar.xz mpd-837bd79b20d4b9b8525a42999a9d1911f8980aa4.zip |
db_lock: add assertions
Diffstat (limited to 'src')
-rw-r--r-- | src/db_lock.c | 4 | ||||
-rw-r--r-- | src/db_lock.h | 29 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/db_lock.c b/src/db_lock.c index 3aaba4dc2..88adc3614 100644 --- a/src/db_lock.c +++ b/src/db_lock.c @@ -21,3 +21,7 @@ #include "db_lock.h" GStaticMutex db_mutex = G_STATIC_MUTEX_INIT; + +#ifndef NDEBUG +GThread *db_mutex_holder; +#endif diff --git a/src/db_lock.h b/src/db_lock.h index 1e557b985..4640502f3 100644 --- a/src/db_lock.h +++ b/src/db_lock.h @@ -30,9 +30,26 @@ #include <glib.h> #include <assert.h> +#include <stdbool.h> extern GStaticMutex db_mutex; +#ifndef NDEBUG + +extern GThread *db_mutex_holder; + +/** + * Does the current thread hold the database lock? + */ +G_GNUC_PURE +static inline bool +holding_db_lock(void) +{ + return db_mutex_holder == g_thread_self(); +} + +#endif + /** * Obtain the global database lock. This is needed before * dereferencing a #song or #directory. It is not recursive. @@ -40,7 +57,14 @@ extern GStaticMutex db_mutex; static inline void db_lock(void) { + assert(!holding_db_lock()); + g_static_mutex_lock(&db_mutex); + + assert(db_mutex_holder == NULL); +#ifndef NDEBUG + db_mutex_holder = g_thread_self(); +#endif } /** @@ -49,6 +73,11 @@ db_lock(void) static inline void db_unlock(void) { + assert(holding_db_lock()); +#ifndef NDEBUG + db_mutex_holder = NULL; +#endif + g_static_mutex_unlock(&db_mutex); } |