db/simple/Directory: RemoveSong() returns SongPtr
This commit is contained in:
src/db
@ -172,7 +172,7 @@ Directory::AddSong(SongPtr song) noexcept
|
|||||||
songs.push_back(*song.release());
|
songs.push_back(*song.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
SongPtr
|
||||||
Directory::RemoveSong(Song *song) noexcept
|
Directory::RemoveSong(Song *song) noexcept
|
||||||
{
|
{
|
||||||
assert(holding_db_lock());
|
assert(holding_db_lock());
|
||||||
@ -180,6 +180,7 @@ Directory::RemoveSong(Song *song) noexcept
|
|||||||
assert(&song->parent == this);
|
assert(&song->parent == this);
|
||||||
|
|
||||||
songs.erase(songs.iterator_to(*song));
|
songs.erase(songs.iterator_to(*song));
|
||||||
|
return SongPtr(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Song *
|
const Song *
|
||||||
|
@ -257,9 +257,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Remove a song object from this directory (which effectively
|
* Remove a song object from this directory (which effectively
|
||||||
* invalidates the song object, because the "parent" attribute becomes
|
* invalidates the song object, because the "parent" attribute becomes
|
||||||
* stale), but does not free it.
|
* stale), and return ownership to the caller.
|
||||||
*/
|
*/
|
||||||
void RemoveSong(Song *song) noexcept;
|
SongPtr RemoveSong(Song *song) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caller must lock the #db_mutex.
|
* Caller must lock the #db_mutex.
|
||||||
|
@ -32,7 +32,7 @@ DatabaseEditor::DeleteSong(Directory &dir, Song *del)
|
|||||||
assert(&del->parent == &dir);
|
assert(&del->parent == &dir);
|
||||||
|
|
||||||
/* first, prevent traversers in main task from getting this */
|
/* first, prevent traversers in main task from getting this */
|
||||||
dir.RemoveSong(del);
|
const SongPtr song = dir.RemoveSong(del);
|
||||||
|
|
||||||
/* temporary unlock, because update_remove_song() blocks */
|
/* temporary unlock, because update_remove_song() blocks */
|
||||||
const ScopeDatabaseUnlock unlock;
|
const ScopeDatabaseUnlock unlock;
|
||||||
@ -40,8 +40,8 @@ DatabaseEditor::DeleteSong(Directory &dir, Song *del)
|
|||||||
/* 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->GetURI());
|
remove.Remove(del->GetURI());
|
||||||
|
|
||||||
/* finally, all possible references gone, free it */
|
/* the Song object will be freed here because its owning
|
||||||
delete del;
|
SongPtr lives on our stack, see above */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user