00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #ifndef MPD_DB_LOCK_H
00027 #define MPD_DB_LOCK_H
00028
00029 #include "check.h"
00030
00031 #include <glib.h>
00032 #include <assert.h>
00033 #include <stdbool.h>
00034
00035 extern GStaticMutex db_mutex;
00036
00037 #ifndef NDEBUG
00038
00039 extern GThread *db_mutex_holder;
00040
00044 G_GNUC_PURE
00045 static inline bool
00046 holding_db_lock(void)
00047 {
00048 return db_mutex_holder == g_thread_self();
00049 }
00050
00051 #endif
00052
00057 static inline void
00058 db_lock(void)
00059 {
00060 assert(!holding_db_lock());
00061
00062 g_static_mutex_lock(&db_mutex);
00063
00064 assert(db_mutex_holder == NULL);
00065 #ifndef NDEBUG
00066 db_mutex_holder = g_thread_self();
00067 #endif
00068 }
00069
00073 static inline void
00074 db_unlock(void)
00075 {
00076 assert(holding_db_lock());
00077 #ifndef NDEBUG
00078 db_mutex_holder = NULL;
00079 #endif
00080
00081 g_static_mutex_unlock(&db_mutex);
00082 }
00083
00084 #endif