diff --git a/src/lib/nfs/Manager.cxx b/src/lib/nfs/Manager.cxx index 8d314429f..22b3c7775 100644 --- a/src/lib/nfs/Manager.cxx +++ b/src/lib/nfs/Manager.cxx @@ -22,10 +22,9 @@ #include "event/Loop.hxx" #include "util/DeleteDisposer.hxx" #include "util/Domain.hxx" +#include "util/StringAPI.hxx" #include "Log.hxx" -#include - static constexpr Domain nfs_domain("nfs"); void @@ -40,42 +39,6 @@ NfsManager::ManagedConnection::OnNfsConnectionError(std::exception_ptr &&e) noex manager.ScheduleDelete(*this); } -inline bool -NfsManager::Compare::operator()(const LookupKey a, - const ManagedConnection &b) const noexcept -{ - int result = strcmp(a.server, b.GetServer()); - if (result != 0) - return result < 0; - - result = strcmp(a.export_name, b.GetExportName()); - return result < 0; -} - -inline bool -NfsManager::Compare::operator()(const ManagedConnection &a, - const LookupKey b) const noexcept -{ - int result = strcmp(a.GetServer(), b.server); - if (result != 0) - return result < 0; - - result = strcmp(a.GetExportName(), b.export_name); - return result < 0; -} - -inline bool -NfsManager::Compare::operator()(const ManagedConnection &a, - const ManagedConnection &b) const noexcept -{ - int result = strcmp(a.GetServer(), b.GetServer()); - if (result != 0) - return result < 0; - - result = strcmp(a.GetExportName(), b.GetExportName()); - return result < 0; -} - NfsManager::~NfsManager() noexcept { assert(!GetEventLoop().IsAlive() || GetEventLoop().IsInside()); @@ -92,17 +55,15 @@ NfsManager::GetConnection(const char *server, const char *export_name) noexcept assert(export_name != nullptr); assert(GetEventLoop().IsInside()); - Map::insert_commit_data hint; - auto result = connections.insert_check(LookupKey{server, export_name}, - Compare(), hint); - if (result.second) { - auto c = new ManagedConnection(*this, GetEventLoop(), - server, export_name); - connections.insert_commit(*c, hint); - return *c; - } else { - return *result.first; - } + for (auto &c : connections) + if (StringIsEqual(server, c.GetServer()) && + StringIsEqual(export_name, c.GetExportName())) + return c; + + auto c = new ManagedConnection(*this, GetEventLoop(), + server, export_name); + connections.push_front(*c); + return *c; } void diff --git a/src/lib/nfs/Manager.hxx b/src/lib/nfs/Manager.hxx index b7983a9c0..cd5c1c62d 100644 --- a/src/lib/nfs/Manager.hxx +++ b/src/lib/nfs/Manager.hxx @@ -22,24 +22,17 @@ #include "Connection.hxx" #include "event/IdleEvent.hxx" -#include "util/IntrusiveForwardList.hxx" - -#include +#include "util/IntrusiveList.hxx" /** * A manager for NFS connections. Handles multiple connections to * multiple NFS servers. */ class NfsManager final { - struct LookupKey { - const char *server; - const char *export_name; - }; - class ManagedConnection final : public NfsConnection, - public IntrusiveForwardListHook, - public boost::intrusive::set_base_hook> { + public IntrusiveListHook<> + { NfsManager &manager; public: @@ -54,30 +47,9 @@ class NfsManager final { void OnNfsConnectionError(std::exception_ptr &&e) noexcept override; }; - struct Compare { - [[gnu::pure]] - bool operator()(const LookupKey a, - const ManagedConnection &b) const noexcept; + using List = IntrusiveList; - [[gnu::pure]] - bool operator()(const ManagedConnection &a, - const LookupKey b) const noexcept; - - [[gnu::pure]] - bool operator()(const ManagedConnection &a, - const ManagedConnection &b) const noexcept; - }; - - /** - * Maps server and export_name to #ManagedConnection. - */ - typedef boost::intrusive::set, - boost::intrusive::constant_time_size> Map; - - Map connections; - - using List = IntrusiveForwardList; + List connections; /** * A list of "garbage" connection objects. Their destruction