diff options
Diffstat (limited to '')
-rw-r--r-- | src/DatabaseLock.hxx (renamed from src/db_lock.h) | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/db_lock.h b/src/DatabaseLock.hxx index 4640502f3..371a7d7b2 100644 --- a/src/db_lock.h +++ b/src/DatabaseLock.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -23,16 +23,16 @@ * multi-threading. */ -#ifndef MPD_DB_LOCK_H -#define MPD_DB_LOCK_H +#ifndef MPD_DB_LOCK_HXX +#define MPD_DB_LOCK_HXX #include "check.h" +#include "thread/Mutex.hxx" #include <glib.h> #include <assert.h> -#include <stdbool.h> -extern GStaticMutex db_mutex; +extern Mutex db_mutex; #ifndef NDEBUG @@ -59,7 +59,7 @@ db_lock(void) { assert(!holding_db_lock()); - g_static_mutex_lock(&db_mutex); + db_mutex.lock(); assert(db_mutex_holder == NULL); #ifndef NDEBUG @@ -78,7 +78,22 @@ db_unlock(void) db_mutex_holder = NULL; #endif - g_static_mutex_unlock(&db_mutex); + db_mutex.unlock(); } +#ifdef __cplusplus + +class ScopeDatabaseLock { +public: + ScopeDatabaseLock() { + db_lock(); + } + + ~ScopeDatabaseLock() { + db_unlock(); + } +}; + +#endif + #endif |