db/simple/{Directory,Song}: use IntrusiveList instead of boost::intrusive::list

This commit is contained in:
Max Kellermann 2021-02-24 20:41:35 +01:00 committed by Max Kellermann
parent a448d04d46
commit 81e1f87e8c
6 changed files with 23 additions and 48 deletions

View File

@ -31,6 +31,7 @@
#include "lib/icu/Collate.hxx"
#include "fs/Traits.hxx"
#include "util/DeleteDisposer.hxx"
#include "util/SortList.hxx"
#include "util/StringCompare.hxx"
#include "util/StringSplit.hxx"
@ -220,7 +221,7 @@ Directory::Sort() noexcept
{
assert(holding_db_lock());
children.sort(directory_cmp);
SortList(children, directory_cmp);
song_list_sort(songs);
for (auto &child : children)

View File

@ -24,9 +24,7 @@
#include "db/Visitor.hxx"
#include "db/PlaylistVector.hxx"
#include "db/Ptr.hxx"
#include "Song.hxx"
#include <boost/intrusive/list.hpp>
#include "util/IntrusiveList.hxx"
#include <string>
#include <string_view>
@ -52,25 +50,12 @@ static constexpr unsigned DEVICE_PLAYLIST = -3;
class SongFilter;
struct Directory {
static constexpr auto link_mode = boost::intrusive::normal_link;
typedef boost::intrusive::link_mode<link_mode> LinkMode;
typedef boost::intrusive::list_member_hook<LinkMode> Hook;
struct Directory : IntrusiveListHook {
/* Note: the #IntrusiveListHook is protected with the global
#db_mutex. Read access in the update thread does not need
protection. */
/**
* Pointers to the siblings of this directory within the
* parent directory. It is unused (undefined) in the root
* directory.
*
* This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection.
*/
Hook siblings;
typedef boost::intrusive::member_hook<Directory, Hook,
&Directory::siblings> SiblingsHook;
typedef boost::intrusive::list<Directory, SiblingsHook,
boost::intrusive::constant_time_size<false>> List;
using List = IntrusiveList<Directory>;
/**
* A doubly linked list of child directories.
@ -86,7 +71,7 @@ struct Directory {
* This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection.
*/
SongList songs;
IntrusiveList<Song> songs;
PlaylistVector playlists;

View File

@ -24,10 +24,9 @@
#include "Chrono.hxx"
#include "tag/Tag.hxx"
#include "pcm/AudioFormat.hxx"
#include "util/IntrusiveList.hxx"
#include "config.h"
#include <boost/intrusive/list.hpp>
#include <string>
struct Directory;
@ -40,20 +39,10 @@ class ArchiveFile;
* A song file inside the configured music directory. Internal
* #SimpleDatabase class.
*/
struct Song {
static constexpr auto link_mode = boost::intrusive::normal_link;
typedef boost::intrusive::link_mode<link_mode> LinkMode;
typedef boost::intrusive::list_member_hook<LinkMode> Hook;
/**
* Pointers to the siblings of this directory within the
* parent directory. It is unused (undefined) if this song is
* not in the database.
*
* This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection.
*/
Hook siblings;
struct Song : IntrusiveListHook {
/* Note: the #IntrusiveListHook is protected with the global
#db_mutex. Read access in the update thread does not need
protection. */
/**
* The #Directory that contains this song.
@ -160,9 +149,4 @@ struct Song {
ExportedSong Export() const noexcept;
};
typedef boost::intrusive::list<Song,
boost::intrusive::member_hook<Song, Song::Hook,
&Song::siblings>,
boost::intrusive::constant_time_size<false>> SongList;
#endif

View File

@ -21,6 +21,8 @@
#include "Song.hxx"
#include "tag/Tag.hxx"
#include "lib/icu/Collate.hxx"
#include "util/IntrusiveList.hxx"
#include "util/SortList.hxx"
#include <stdlib.h>
@ -100,7 +102,7 @@ song_cmp(const Song &a, const Song &b) noexcept
}
void
song_list_sort(SongList &songs) noexcept
song_list_sort(IntrusiveList<Song> &songs) noexcept
{
songs.sort(song_cmp);
SortList(songs, song_cmp);
}

View File

@ -20,9 +20,11 @@
#ifndef MPD_SONG_SORT_HXX
#define MPD_SONG_SORT_HXX
#include "Song.hxx"
#include "util/IntrusiveList.hxx"
struct Song;
void
song_list_sort(SongList &songs) noexcept;
song_list_sort(IntrusiveList<Song> &songs) noexcept;
#endif

View File

@ -22,6 +22,7 @@
#include "db/DatabaseLock.hxx"
#include "db/PlaylistVector.hxx"
#include "db/plugins/simple/Directory.hxx"
#include "db/plugins/simple/Song.hxx"
#include "lib/fmt/ExceptionFormatter.hxx"
#include "song/DetachedSong.hxx"
#include "input/InputStream.hxx"