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,
"No such song");
light_song = song->Export();
light_song.Construct(song->Export());
#ifndef NDEBUG
++borrowed_song_count;
#endif
return &light_song;
return &light_song.Get();
}
void
SimpleDatabase::ReturnSong(gcc_unused const LightSong *song) const
{
assert(song != nullptr);
assert(song == &light_song || song == prefixed_light_song);
delete prefixed_light_song;
prefixed_light_song = nullptr;
assert(song == &light_song.Get() || song == prefixed_light_song);
if (prefixed_light_song != nullptr) {
delete prefixed_light_song;
prefixed_light_song = nullptr;
} else {
#ifndef NDEBUG
if (song == &light_song) {
assert(borrowed_song_count > 0);
--borrowed_song_count;
}
#endif
light_song.Destruct();
}
}
void

View File

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