db/simple: wrap LightSong in Manual<>

Prepare to make LightSong non-assignable.
This commit is contained in:
Max Kellermann 2018-07-06 16:46:01 +02:00
parent 86a02871fc
commit ebc006ab52
2 changed files with 12 additions and 9 deletions

View File

@ -237,30 +237,32 @@ SimpleDatabase::GetSong(const char *uri) const
throw DatabaseError(DatabaseErrorCode::NOT_FOUND, throw DatabaseError(DatabaseErrorCode::NOT_FOUND,
"No such song"); "No such song");
light_song = song->Export(); light_song.Construct(song->Export());
#ifndef NDEBUG #ifndef NDEBUG
++borrowed_song_count; ++borrowed_song_count;
#endif #endif
return &light_song; return &light_song.Get();
} }
void void
SimpleDatabase::ReturnSong(gcc_unused const LightSong *song) const SimpleDatabase::ReturnSong(gcc_unused const LightSong *song) const
{ {
assert(song != nullptr); assert(song != nullptr);
assert(song == &light_song || song == prefixed_light_song); assert(song == &light_song.Get() || song == prefixed_light_song);
if (prefixed_light_song != nullptr) {
delete prefixed_light_song; delete prefixed_light_song;
prefixed_light_song = nullptr; prefixed_light_song = nullptr;
} else {
#ifndef NDEBUG #ifndef NDEBUG
if (song == &light_song) {
assert(borrowed_song_count > 0); assert(borrowed_song_count > 0);
--borrowed_song_count; --borrowed_song_count;
}
#endif #endif
light_song.Destruct();
}
} }
void void

View File

@ -24,6 +24,7 @@
#include "db/Interface.hxx" #include "db/Interface.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "db/LightSong.hxx" #include "db/LightSong.hxx"
#include "util/Manual.hxx"
#include "Compiler.h" #include "Compiler.h"
#include <cassert> #include <cassert>
@ -61,7 +62,7 @@ class SimpleDatabase : public Database {
/** /**
* A buffer for GetSong(). * A buffer for GetSong().
*/ */
mutable LightSong light_song; mutable Manual<LightSong> light_song;
#ifndef NDEBUG #ifndef NDEBUG
mutable unsigned borrowed_song_count; mutable unsigned borrowed_song_count;