Commit 3ca0a39a authored by Max Kellermann's avatar Max Kellermann

db/simple: use class boost::intrusive::list

Remove the C list_head library and use type-safe C++ instead.
parent 52594e64
...@@ -370,8 +370,6 @@ libutil_a_SOURCES = \ ...@@ -370,8 +370,6 @@ libutil_a_SOURCES = \
src/util/PeakBuffer.cxx src/util/PeakBuffer.hxx \ src/util/PeakBuffer.cxx src/util/PeakBuffer.hxx \
src/util/OptionParser.cxx src/util/OptionParser.hxx \ src/util/OptionParser.cxx src/util/OptionParser.hxx \
src/util/OptionDef.hxx \ src/util/OptionDef.hxx \
src/util/list.h \
src/util/list_sort.c src/util/list_sort.h \
src/util/ByteReverse.cxx src/util/ByteReverse.hxx \ src/util/ByteReverse.cxx src/util/ByteReverse.hxx \
src/util/bit_reverse.c src/util/bit_reverse.h src/util/bit_reverse.c src/util/bit_reverse.h
......
...@@ -33,10 +33,6 @@ ...@@ -33,10 +33,6 @@
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
extern "C" {
#include "util/list_sort.h"
}
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -47,21 +43,14 @@ Directory::Directory(std::string &&_path_utf8, Directory *_parent) ...@@ -47,21 +43,14 @@ Directory::Directory(std::string &&_path_utf8, Directory *_parent)
path(std::move(_path_utf8)), path(std::move(_path_utf8)),
mounted_database(nullptr) mounted_database(nullptr)
{ {
INIT_LIST_HEAD(&children);
INIT_LIST_HEAD(&songs);
} }
Directory::~Directory() Directory::~Directory()
{ {
delete mounted_database; delete mounted_database;
Song *song, *ns; songs.clear_and_dispose(Song::Disposer());
directory_for_each_song_safe(song, ns, *this) children.clear_and_dispose(Disposer());
song->Free();
Directory *child, *n;
directory_for_each_child_safe(child, n, *this)
delete child;
} }
void void
...@@ -70,8 +59,8 @@ Directory::Delete() ...@@ -70,8 +59,8 @@ Directory::Delete()
assert(holding_db_lock()); assert(holding_db_lock());
assert(parent != nullptr); assert(parent != nullptr);
list_del(&siblings); parent->children.erase_and_dispose(parent->children.iterator_to(*this),
delete this; Disposer());
} }
const char * const char *
...@@ -94,7 +83,7 @@ Directory::CreateChild(const char *name_utf8) ...@@ -94,7 +83,7 @@ Directory::CreateChild(const char *name_utf8)
: PathTraitsUTF8::Build(GetPath(), name_utf8); : PathTraitsUTF8::Build(GetPath(), name_utf8);
Directory *child = new Directory(std::move(path_utf8), this); Directory *child = new Directory(std::move(path_utf8), this);
list_add_tail(&child->siblings, &children); children.push_back(*child);
return child; return child;
} }
...@@ -103,10 +92,9 @@ Directory::FindChild(const char *name) const ...@@ -103,10 +92,9 @@ Directory::FindChild(const char *name) const
{ {
assert(holding_db_lock()); assert(holding_db_lock());
const Directory *child; for (const auto &child : children)
directory_for_each_child(child, *this) if (strcmp(child.GetName(), name) == 0)
if (strcmp(child->GetName(), name) == 0) return &child;
return child;
return nullptr; return nullptr;
} }
...@@ -116,17 +104,14 @@ Directory::PruneEmpty() ...@@ -116,17 +104,14 @@ Directory::PruneEmpty()
{ {
assert(holding_db_lock()); assert(holding_db_lock());
Directory *child, *n; for (auto child = children.begin(), end = children.end();
directory_for_each_child_safe(child, n, *this) { child != end;) {
if (child->IsMount())
/* never prune mount points; they're always
empty by definition, but that's ok */
continue;
child->PruneEmpty(); child->PruneEmpty();
if (child->IsEmpty()) if (child->IsEmpty())
child->Delete(); child = children.erase_and_dispose(child, Disposer());
else
++child;
} }
} }
...@@ -182,7 +167,7 @@ Directory::AddSong(Song *song) ...@@ -182,7 +167,7 @@ Directory::AddSong(Song *song)
assert(song != nullptr); assert(song != nullptr);
assert(song->parent == this); assert(song->parent == this);
list_add_tail(&song->siblings, &songs); songs.push_back(*song);
} }
void void
...@@ -192,7 +177,7 @@ Directory::RemoveSong(Song *song) ...@@ -192,7 +177,7 @@ Directory::RemoveSong(Song *song)
assert(song != nullptr); assert(song != nullptr);
assert(song->parent == this); assert(song->parent == this);
list_del(&song->siblings); songs.erase(songs.iterator_to(*song));
} }
const Song * const Song *
...@@ -201,25 +186,21 @@ Directory::FindSong(const char *name_utf8) const ...@@ -201,25 +186,21 @@ Directory::FindSong(const char *name_utf8) const
assert(holding_db_lock()); assert(holding_db_lock());
assert(name_utf8 != nullptr); assert(name_utf8 != nullptr);
Song *song; for (auto &song : songs) {
directory_for_each_song(song, *this) { assert(song.parent == this);
assert(song->parent == this);
if (strcmp(song->uri, name_utf8) == 0) if (strcmp(song.uri, name_utf8) == 0)
return song; return &song;
} }
return nullptr; return nullptr;
} }
static int gcc_pure
directory_cmp(gcc_unused void *priv, static bool
struct list_head *_a, struct list_head *_b) directory_cmp(const Directory &a, const Directory &b)
{ {
const Directory *a = (const Directory *)_a; return IcuCollate(a.path.c_str(), b.path.c_str()) < 0;
const Directory *b = (const Directory *)_b;
return IcuCollate(a->path.c_str(), b->path.c_str());
} }
void void
...@@ -227,12 +208,11 @@ Directory::Sort() ...@@ -227,12 +208,11 @@ Directory::Sort()
{ {
assert(holding_db_lock()); assert(holding_db_lock());
list_sort(nullptr, &children, directory_cmp); children.sort(directory_cmp);
song_list_sort(&songs); song_list_sort(songs);
Directory *child; for (auto &child : children)
directory_for_each_child(child, *this) child.Sort();
child->Sort();
} }
bool bool
...@@ -260,9 +240,8 @@ Directory::Walk(bool recursive, const SongFilter *filter, ...@@ -260,9 +240,8 @@ Directory::Walk(bool recursive, const SongFilter *filter,
} }
if (visit_song) { if (visit_song) {
Song *song; for (auto &song : songs){
directory_for_each_song(song, *this) { const LightSong song2 = song.Export();
const LightSong song2 = song->Export();
if ((filter == nullptr || filter->Match(song2)) && if ((filter == nullptr || filter->Match(song2)) &&
!visit_song(song2, error)) !visit_song(song2, error))
return false; return false;
...@@ -275,16 +254,15 @@ Directory::Walk(bool recursive, const SongFilter *filter, ...@@ -275,16 +254,15 @@ Directory::Walk(bool recursive, const SongFilter *filter,
return false; return false;
} }
Directory *child; for (auto &child : children) {
directory_for_each_child(child, *this) {
if (visit_directory && if (visit_directory &&
!visit_directory(child->Export(), error)) !visit_directory(child.Export(), error))
return false; return false;
if (recursive && if (recursive &&
!child->Walk(recursive, filter, !child.Walk(recursive, filter,
visit_directory, visit_song, visit_playlist, visit_directory, visit_song, visit_playlist,
error)) error))
return false; return false;
} }
......
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
#define MPD_DIRECTORY_HXX #define MPD_DIRECTORY_HXX
#include "check.h" #include "check.h"
#include "util/list.h"
#include "Compiler.h" #include "Compiler.h"
#include "db/Visitor.hxx" #include "db/Visitor.hxx"
#include "db/PlaylistVector.hxx" #include "db/PlaylistVector.hxx"
#include "Song.hxx"
#include <boost/intrusive/list.hpp>
#include <string> #include <string>
...@@ -41,25 +43,22 @@ static constexpr unsigned DEVICE_INARCHIVE = -1; ...@@ -41,25 +43,22 @@ static constexpr unsigned DEVICE_INARCHIVE = -1;
*/ */
static constexpr unsigned DEVICE_CONTAINER = -2; static constexpr unsigned DEVICE_CONTAINER = -2;
#define directory_for_each_child(pos, directory) \
list_for_each_entry(pos, &(directory).children, siblings)
#define directory_for_each_child_safe(pos, n, directory) \
list_for_each_entry_safe(pos, n, &(directory).children, siblings)
#define directory_for_each_song(pos, directory) \
list_for_each_entry(pos, &(directory).songs, siblings)
#define directory_for_each_song_safe(pos, n, directory) \
list_for_each_entry_safe(pos, n, &(directory).songs, siblings)
struct Song;
struct db_visitor; struct db_visitor;
class SongFilter; class SongFilter;
class Error; class Error;
class Database; class Database;
struct Directory { 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 Disposer {
void operator()(Directory *directory) const {
delete directory;
}
};
/** /**
* Pointers to the siblings of this directory within the * Pointers to the siblings of this directory within the
* parent directory. It is unused (undefined) in the root * parent directory. It is unused (undefined) in the root
...@@ -68,7 +67,12 @@ struct Directory { ...@@ -68,7 +67,12 @@ struct Directory {
* This attribute is protected with the global #db_mutex. * This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection. * Read access in the update thread does not need protection.
*/ */
struct list_head siblings; 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;
/** /**
* A doubly linked list of child directories. * A doubly linked list of child directories.
...@@ -76,7 +80,7 @@ struct Directory { ...@@ -76,7 +80,7 @@ struct Directory {
* This attribute is protected with the global #db_mutex. * This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection. * Read access in the update thread does not need protection.
*/ */
struct list_head children; List children;
/** /**
* A doubly linked list of songs within this directory. * A doubly linked list of songs within this directory.
...@@ -84,7 +88,7 @@ struct Directory { ...@@ -84,7 +88,7 @@ struct Directory {
* This attribute is protected with the global #db_mutex. * This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection. * Read access in the update thread does not need protection.
*/ */
struct list_head songs; SongList songs;
PlaylistVector playlists; PlaylistVector playlists;
...@@ -186,8 +190,8 @@ public: ...@@ -186,8 +190,8 @@ public:
gcc_pure gcc_pure
bool IsEmpty() const { bool IsEmpty() const {
return list_empty(&children) && return children.empty() &&
list_empty(&songs) && songs.empty() &&
playlists.empty(); playlists.empty();
} }
...@@ -210,6 +214,24 @@ public: ...@@ -210,6 +214,24 @@ public:
return parent == nullptr; return parent == nullptr;
} }
template<typename T>
void ForEachChildSafe(T &&t) {
const auto end = children.end();
for (auto i = children.begin(), next = i; i != end; i = next) {
next = std::next(i);
t(*i);
}
}
template<typename T>
void ForEachSongSafe(T &&t) {
const auto end = songs.end();
for (auto i = songs.begin(), next = i; i != end; i = next) {
next = std::next(i);
t(*i);
}
}
/** /**
* Look up a song in this directory by its name. * Look up a song in this directory by its name.
* *
......
...@@ -84,20 +84,18 @@ directory_save(FILE *fp, const Directory &directory) ...@@ -84,20 +84,18 @@ directory_save(FILE *fp, const Directory &directory)
fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, directory.GetPath()); fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, directory.GetPath());
} }
Directory *cur; for (const auto &child : directory.children) {
directory_for_each_child(cur, directory) { fprintf(fp, DIRECTORY_DIR "%s\n", child.GetName());
fprintf(fp, DIRECTORY_DIR "%s\n", cur->GetName());
if (!cur->IsMount()) if (!child.IsMount())
directory_save(fp, *cur); directory_save(fp, child);
if (ferror(fp)) if (ferror(fp))
return; return;
} }
Song *song; for (const auto &song : directory.songs)
directory_for_each_song(song, directory) song_save(fp, song);
song_save(fp, *song);
playlist_vector_save(fp, directory.playlists); playlist_vector_save(fp, directory.playlists);
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
#ifndef MPD_SONG_HXX #ifndef MPD_SONG_HXX
#define MPD_SONG_HXX #define MPD_SONG_HXX
#include "util/list.h"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "Compiler.h" #include "Compiler.h"
#include <boost/intrusive/list.hpp>
#include <string> #include <string>
#include <assert.h> #include <assert.h>
...@@ -39,6 +40,16 @@ class Storage; ...@@ -39,6 +40,16 @@ class Storage;
* #SimpleDatabase class. * #SimpleDatabase class.
*/ */
struct Song { 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;
struct Disposer {
void operator()(Song *song) const {
song->Free();
}
};
/** /**
* Pointers to the siblings of this directory within the * Pointers to the siblings of this directory within the
* parent directory. It is unused (undefined) if this song is * parent directory. It is unused (undefined) if this song is
...@@ -47,7 +58,7 @@ struct Song { ...@@ -47,7 +58,7 @@ struct Song {
* This attribute is protected with the global #db_mutex. * This attribute is protected with the global #db_mutex.
* Read access in the update thread does not need protection. * Read access in the update thread does not need protection.
*/ */
struct list_head siblings; Hook siblings;
Tag tag; Tag tag;
...@@ -110,4 +121,9 @@ struct Song { ...@@ -110,4 +121,9 @@ struct Song {
LightSong Export() const; LightSong Export() const;
}; };
typedef boost::intrusive::list<Song,
boost::intrusive::member_hook<Song, Song::Hook,
&Song::siblings>,
boost::intrusive::constant_time_size<false>> SongList;
#endif #endif
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "lib/icu/Collate.hxx" #include "lib/icu/Collate.hxx"
extern "C" {
#include "util/list_sort.h"
}
#include <stdlib.h> #include <stdlib.h>
static int static int
...@@ -80,34 +76,33 @@ compare_tag_item(const Tag &a, const Tag &b, TagType type) ...@@ -80,34 +76,33 @@ compare_tag_item(const Tag &a, const Tag &b, TagType type)
} }
/* Only used for sorting/searchin a songvec, not general purpose compares */ /* Only used for sorting/searchin a songvec, not general purpose compares */
static int gcc_pure
song_cmp(gcc_unused void *priv, struct list_head *_a, struct list_head *_b) static bool
song_cmp(const Song &a, const Song &b)
{ {
const Song *a = (const Song *)_a;
const Song *b = (const Song *)_b;
int ret; int ret;
/* first sort by album */ /* first sort by album */
ret = compare_string_tag_item(a->tag, b->tag, TAG_ALBUM); ret = compare_string_tag_item(a.tag, b.tag, TAG_ALBUM);
if (ret != 0) if (ret != 0)
return ret; return ret < 0;
/* then sort by disc */ /* then sort by disc */
ret = compare_tag_item(a->tag, b->tag, TAG_DISC); ret = compare_tag_item(a.tag, b.tag, TAG_DISC);
if (ret != 0) if (ret != 0)
return ret; return ret < 0;
/* then by track number */ /* then by track number */
ret = compare_tag_item(a->tag, b->tag, TAG_TRACK); ret = compare_tag_item(a.tag, b.tag, TAG_TRACK);
if (ret != 0) if (ret != 0)
return ret; return ret < 0;
/* still no difference? compare file name */ /* still no difference? compare file name */
return IcuCollate(a->uri, b->uri); return IcuCollate(a.uri, b.uri) < 0;
} }
void void
song_list_sort(struct list_head *songs) song_list_sort(SongList &songs)
{ {
list_sort(nullptr, songs, song_cmp); songs.sort(song_cmp);
} }
...@@ -20,9 +20,11 @@ ...@@ -20,9 +20,11 @@
#ifndef MPD_SONG_SORT_HXX #ifndef MPD_SONG_SORT_HXX
#define MPD_SONG_SORT_HXX #define MPD_SONG_SORT_HXX
#include "Song.hxx"
struct list_head; struct list_head;
void void
song_list_sort(list_head *songs); song_list_sort(SongList &songs);
#endif #endif
...@@ -64,15 +64,14 @@ DatabaseEditor::LockDeleteSong(Directory &parent, Song *song) ...@@ -64,15 +64,14 @@ DatabaseEditor::LockDeleteSong(Directory &parent, Song *song)
inline void inline void
DatabaseEditor::ClearDirectory(Directory &directory) DatabaseEditor::ClearDirectory(Directory &directory)
{ {
Directory *child, *n; directory.ForEachChildSafe([this](Directory &child){
directory_for_each_child_safe(child, n, directory) DeleteDirectory(&child);
DeleteDirectory(child); });
Song *song, *ns; directory.ForEachSongSafe([this, &directory](Song &song){
directory_for_each_song_safe(song, ns, directory) { assert(song.parent == &directory);
assert(song->parent == &directory); DeleteSong(directory, &song);
DeleteSong(directory, song); });
}
} }
void void
......
...@@ -80,26 +80,25 @@ UpdateWalk::RemoveExcludedFromDirectory(Directory &directory, ...@@ -80,26 +80,25 @@ UpdateWalk::RemoveExcludedFromDirectory(Directory &directory,
{ {
db_lock(); db_lock();
Directory *child, *n; directory.ForEachChildSafe([&](Directory &child){
directory_for_each_child_safe(child, n, directory) { const auto name_fs =
const auto name_fs = AllocatedPath::FromUTF8(child->GetName()); AllocatedPath::FromUTF8(child.GetName());
if (name_fs.IsNull() || exclude_list.Check(name_fs)) { if (name_fs.IsNull() || exclude_list.Check(name_fs)) {
editor.DeleteDirectory(child); editor.DeleteDirectory(&child);
modified = true; modified = true;
} }
} });
Song *song, *ns; directory.ForEachSongSafe([&](Song &song){
directory_for_each_song_safe(song, ns, directory) { assert(song.parent == &directory);
assert(song->parent == &directory);
const auto name_fs = AllocatedPath::FromUTF8(song->uri); const auto name_fs = AllocatedPath::FromUTF8(song.uri);
if (name_fs.IsNull() || exclude_list.Check(name_fs)) { if (name_fs.IsNull() || exclude_list.Check(name_fs)) {
editor.DeleteSong(directory, song); editor.DeleteSong(directory, &song);
modified = true; modified = true;
} }
} });
db_unlock(); db_unlock();
} }
...@@ -107,25 +106,23 @@ UpdateWalk::RemoveExcludedFromDirectory(Directory &directory, ...@@ -107,25 +106,23 @@ UpdateWalk::RemoveExcludedFromDirectory(Directory &directory,
inline void inline void
UpdateWalk::PurgeDeletedFromDirectory(Directory &directory) UpdateWalk::PurgeDeletedFromDirectory(Directory &directory)
{ {
Directory *child, *n; directory.ForEachChildSafe([&](Directory &child){
directory_for_each_child_safe(child, n, directory) { if (DirectoryExists(storage, child))
if (DirectoryExists(storage, *child)) return;
continue;
editor.LockDeleteDirectory(child); editor.LockDeleteDirectory(&child);
modified = true; modified = true;
} });
Song *song, *ns; directory.ForEachSongSafe([&](Song &song){
directory_for_each_song_safe(song, ns, directory) { if (!directory_child_is_regular(storage, directory,
if (!directory_child_is_regular(storage, directory, song.uri)) {
song->uri)) { editor.LockDeleteSong(directory, &song);
editor.LockDeleteSong(directory, song);
modified = true; modified = true;
} }
} });
for (auto i = directory.playlists.begin(), for (auto i = directory.playlists.begin(),
end = directory.playlists.end(); end = directory.playlists.end();
......
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* This code was imported from the Linux kernel.
*
*/
#include "list_sort.h"
#include "list.h"
#include "Macros.hxx"
#include "Compiler.h"
#include <string.h>
#define unlikely gcc_unlikely
#define MAX_LIST_LENGTH_BITS 20
/*
* Returns a list organized in an intermediate format suited
* to chaining of merge() calls: null-terminated, no reserved or
* sentinel head node, "prev" links not maintained.
*/
static struct list_head *merge(void *priv,
int (*cmp)(void *priv, struct list_head *a,
struct list_head *b),
struct list_head *a, struct list_head *b)
{
struct list_head head, *tail = &head;
while (a && b) {
/* if equal, take 'a' -- important for sort stability */
if ((*cmp)(priv, a, b) <= 0) {
tail->next = a;
a = a->next;
} else {
tail->next = b;
b = b->next;
}
tail = tail->next;
}
tail->next = a?a:b;
return head.next;
}
/*
* Combine final list merge with restoration of standard doubly-linked
* list structure. This approach duplicates code from merge(), but
* runs faster than the tidier alternatives of either a separate final
* prev-link restoration pass, or maintaining the prev links
* throughout.
*/
static void merge_and_restore_back_links(void *priv,
int (*cmp)(void *priv, struct list_head *a,
struct list_head *b),
struct list_head *head,
struct list_head *a, struct list_head *b)
{
struct list_head *tail = head;
while (a && b) {
/* if equal, take 'a' -- important for sort stability */
if ((*cmp)(priv, a, b) <= 0) {
tail->next = a;
a->prev = tail;
a = a->next;
} else {
tail->next = b;
b->prev = tail;
b = b->next;
}
tail = tail->next;
}
tail->next = a ? a : b;
do {
/*
* In worst cases this loop may run many iterations.
* Continue callbacks to the client even though no
* element comparison is needed, so the client's cmp()
* routine can invoke cond_resched() periodically.
*/
(*cmp)(priv, tail->next, tail->next);
tail->next->prev = tail;
tail = tail->next;
} while (tail->next);
tail->next = head;
head->prev = tail;
}
/**
* list_sort - sort a list
* @priv: private data, opaque to list_sort(), passed to @cmp
* @head: the list to sort
* @cmp: the elements comparison function
*
* This function implements "merge sort", which has O(nlog(n))
* complexity.
*
* The comparison function @cmp must return a negative value if @a
* should sort before @b, and a positive value if @a should sort after
* @b. If @a and @b are equivalent, and their original relative
* ordering is to be preserved, @cmp must return 0.
*/
void list_sort(void *priv, struct list_head *head,
int (*cmp)(void *priv, struct list_head *a,
struct list_head *b))
{
struct list_head *part[MAX_LIST_LENGTH_BITS+1]; /* sorted partial lists
-- last slot is a sentinel */
int lev; /* index into part[] */
int max_lev = 0;
struct list_head *list;
if (list_empty(head))
return;
memset(part, 0, sizeof(part));
head->prev->next = NULL;
list = head->next;
while (list) {
struct list_head *cur = list;
list = list->next;
cur->next = NULL;
for (lev = 0; part[lev]; lev++) {
cur = merge(priv, cmp, part[lev], cur);
part[lev] = NULL;
}
if (lev > max_lev) {
max_lev = lev;
}
part[lev] = cur;
}
for (lev = 0; lev < max_lev; lev++)
if (part[lev])
list = merge(priv, cmp, part[lev], list);
merge_and_restore_back_links(priv, cmp, head, part[max_lev], list);
}
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* This code was imported from the Linux kernel.
*
*/
#ifndef _LINUX_LIST_SORT_H
#define _LINUX_LIST_SORT_H
struct list_head;
void list_sort(void *priv, struct list_head *head,
int (*cmp)(void *priv, struct list_head *a,
struct list_head *b));
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment