diff options
author | Max Kellermann <max@duempel.org> | 2012-09-05 20:50:15 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-09-05 20:52:02 +0200 |
commit | 0240e75426f483ff558422f99e29708e3f31fdb7 (patch) | |
tree | 29e11cef619d041210393ae1bcf03901b1d4e570 /src | |
parent | 7102ed802638e31f8a8391b51a2989cd087748d1 (diff) | |
download | mpd-0240e75426f483ff558422f99e29708e3f31fdb7.tar.gz mpd-0240e75426f483ff558422f99e29708e3f31fdb7.tar.xz mpd-0240e75426f483ff558422f99e29708e3f31fdb7.zip |
db_lock: add C++ helper class ScopeDatabaseLock
Diffstat (limited to 'src')
-rw-r--r-- | src/db/SimpleDatabasePlugin.cxx | 17 | ||||
-rw-r--r-- | src/db_lock.h | 15 |
2 files changed, 21 insertions, 11 deletions
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx index 54441f4cd..1e5ffe9bb 100644 --- a/src/db/SimpleDatabasePlugin.cxx +++ b/src/db/SimpleDatabasePlugin.cxx @@ -250,11 +250,8 @@ SimpleDatabase::LookupDirectory(const char *uri) const assert(root != NULL); assert(uri != NULL); - db_lock(); - struct directory *directory = - directory_lookup_directory(root, uri); - db_unlock(); - return directory; + ScopeDatabaseLock protect; + return directory_lookup_directory(root, uri); } bool @@ -281,12 +278,10 @@ SimpleDatabase::Visit(const DatabaseSelection &selection, !visit_directory(*directory, error_r)) return false; - db_lock(); - bool ret = directory->Walk(selection.recursive, selection.filter, - visit_directory, visit_song, visit_playlist, - error_r); - db_unlock(); - return ret; + ScopeDatabaseLock protect; + return directory->Walk(selection.recursive, selection.filter, + visit_directory, visit_song, visit_playlist, + error_r); } bool diff --git a/src/db_lock.h b/src/db_lock.h index 4640502f3..eed71eec0 100644 --- a/src/db_lock.h +++ b/src/db_lock.h @@ -81,4 +81,19 @@ db_unlock(void) g_static_mutex_unlock(&db_mutex); } +#ifdef __cplusplus + +class ScopeDatabaseLock { +public: + ScopeDatabaseLock() { + db_lock(); + } + + ~ScopeDatabaseLock() { + db_unlock(); + } +}; + +#endif + #endif |