From 81e1f87e8caacdee11a5115f7b7a5e8958f7e096 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 24 Feb 2021 20:41:35 +0100 Subject: [PATCH] db/simple/{Directory,Song}: use IntrusiveList instead of boost::intrusive::list --- src/db/plugins/simple/Directory.cxx | 3 ++- src/db/plugins/simple/Directory.hxx | 29 +++++++---------------------- src/db/plugins/simple/Song.hxx | 26 +++++--------------------- src/db/plugins/simple/SongSort.cxx | 6 ++++-- src/db/plugins/simple/SongSort.hxx | 6 ++++-- src/db/update/Playlist.cxx | 1 + 6 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/db/plugins/simple/Directory.cxx b/src/db/plugins/simple/Directory.cxx index 102ff42ff..d0cd8138f 100644 --- a/src/db/plugins/simple/Directory.cxx +++ b/src/db/plugins/simple/Directory.cxx @@ -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) diff --git a/src/db/plugins/simple/Directory.hxx b/src/db/plugins/simple/Directory.hxx index fe58e9236..eb69c431a 100644 --- a/src/db/plugins/simple/Directory.hxx +++ b/src/db/plugins/simple/Directory.hxx @@ -24,9 +24,7 @@ #include "db/Visitor.hxx" #include "db/PlaylistVector.hxx" #include "db/Ptr.hxx" -#include "Song.hxx" - -#include +#include "util/IntrusiveList.hxx" #include #include @@ -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 LinkMode; - typedef boost::intrusive::list_member_hook 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 SiblingsHook; - typedef boost::intrusive::list> List; + using List = IntrusiveList; /** * 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 songs; PlaylistVector playlists; diff --git a/src/db/plugins/simple/Song.hxx b/src/db/plugins/simple/Song.hxx index a93b047c8..17b6b6a83 100644 --- a/src/db/plugins/simple/Song.hxx +++ b/src/db/plugins/simple/Song.hxx @@ -24,10 +24,9 @@ #include "Chrono.hxx" #include "tag/Tag.hxx" #include "pcm/AudioFormat.hxx" +#include "util/IntrusiveList.hxx" #include "config.h" -#include - #include 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 LinkMode; - typedef boost::intrusive::list_member_hook 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, - boost::intrusive::constant_time_size> SongList; - #endif diff --git a/src/db/plugins/simple/SongSort.cxx b/src/db/plugins/simple/SongSort.cxx index 0e365c233..9cc256a48 100644 --- a/src/db/plugins/simple/SongSort.cxx +++ b/src/db/plugins/simple/SongSort.cxx @@ -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 @@ -100,7 +102,7 @@ song_cmp(const Song &a, const Song &b) noexcept } void -song_list_sort(SongList &songs) noexcept +song_list_sort(IntrusiveList &songs) noexcept { - songs.sort(song_cmp); + SortList(songs, song_cmp); } diff --git a/src/db/plugins/simple/SongSort.hxx b/src/db/plugins/simple/SongSort.hxx index 2ed00f245..4359679ab 100644 --- a/src/db/plugins/simple/SongSort.hxx +++ b/src/db/plugins/simple/SongSort.hxx @@ -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 &songs) noexcept; #endif diff --git a/src/db/update/Playlist.cxx b/src/db/update/Playlist.cxx index fc5a95e0e..b54009c18 100644 --- a/src/db/update/Playlist.cxx +++ b/src/db/update/Playlist.cxx @@ -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"