db/DatabaseLock: add class ScopeDatabaseUnlock
This commit is contained in:
parent
e31f0b8b0c
commit
c11345c4d9
@ -107,4 +107,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlock the database while in the current scope.
|
||||||
|
*/
|
||||||
|
class ScopeDatabaseUnlock {
|
||||||
|
public:
|
||||||
|
ScopeDatabaseUnlock() {
|
||||||
|
db_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~ScopeDatabaseUnlock() {
|
||||||
|
db_lock();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -232,14 +232,12 @@ Directory::Walk(bool recursive, const SongFilter *filter,
|
|||||||
/* TODO: eliminate this unlock/lock; it is necessary
|
/* TODO: eliminate this unlock/lock; it is necessary
|
||||||
because the child's SimpleDatabasePlugin::Visit()
|
because the child's SimpleDatabasePlugin::Visit()
|
||||||
call will lock it again */
|
call will lock it again */
|
||||||
db_unlock();
|
const ScopeDatabaseUnlock unlock;
|
||||||
bool result = WalkMount(GetPath(), *mounted_database,
|
return WalkMount(GetPath(), *mounted_database,
|
||||||
recursive, filter,
|
recursive, filter,
|
||||||
visit_directory, visit_song,
|
visit_directory, visit_song,
|
||||||
visit_playlist,
|
visit_playlist,
|
||||||
error);
|
error);
|
||||||
db_lock();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visit_song) {
|
if (visit_song) {
|
||||||
|
@ -36,15 +36,14 @@ DatabaseEditor::DeleteSong(Directory &dir, Song *del)
|
|||||||
/* first, prevent traversers in main task from getting this */
|
/* first, prevent traversers in main task from getting this */
|
||||||
dir.RemoveSong(del);
|
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) */
|
/* now take it out of the playlist (in the main_task) */
|
||||||
remove.Remove(del);
|
remove.Remove(del);
|
||||||
|
|
||||||
/* finally, all possible references gone, free it */
|
/* finally, all possible references gone, free it */
|
||||||
del->Free();
|
del->Free();
|
||||||
|
|
||||||
db_lock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user