Commit c11345c4 authored by Max Kellermann's avatar Max Kellermann

db/DatabaseLock: add class ScopeDatabaseUnlock

parent e31f0b8b
......@@ -107,4 +107,18 @@ public:
}
};
/**
* Unlock the database while in the current scope.
*/
class ScopeDatabaseUnlock {
public:
ScopeDatabaseUnlock() {
db_unlock();
}
~ScopeDatabaseUnlock() {
db_lock();
}
};
#endif
......@@ -232,14 +232,12 @@ Directory::Walk(bool recursive, const SongFilter *filter,
/* TODO: eliminate this unlock/lock; it is necessary
because the child's SimpleDatabasePlugin::Visit()
call will lock it again */
db_unlock();
bool result = WalkMount(GetPath(), *mounted_database,
recursive, filter,
visit_directory, visit_song,
visit_playlist,
error);
db_lock();
return result;
const ScopeDatabaseUnlock unlock;
return WalkMount(GetPath(), *mounted_database,
recursive, filter,
visit_directory, visit_song,
visit_playlist,
error);
}
if (visit_song) {
......
......@@ -36,15 +36,14 @@ DatabaseEditor::DeleteSong(Directory &dir, Song *del)
/* first, prevent traversers in main task from getting this */
dir.RemoveSong(del);
db_unlock(); /* temporary unlock, because update_remove_song() blocks */
/* temporary unlock, because update_remove_song() blocks */
const ScopeDatabaseUnlock unlock;
/* now take it out of the playlist (in the main_task) */
remove.Remove(del);
/* finally, all possible references gone, free it */
del->Free();
db_lock();
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment