lib/nfs/Manager: use IntrusiveList instead of boost::intrusive::set
MPD usually has only one NFS connection, maybe two, so managing them in a tree seems like overkill, and since we want to get rid of Boost anyway...
This commit is contained in:
parent
5844242cfb
commit
bafde1900b
|
@ -22,10 +22,9 @@
|
||||||
#include "event/Loop.hxx"
|
#include "event/Loop.hxx"
|
||||||
#include "util/DeleteDisposer.hxx"
|
#include "util/DeleteDisposer.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
|
#include "util/StringAPI.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static constexpr Domain nfs_domain("nfs");
|
static constexpr Domain nfs_domain("nfs");
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -40,42 +39,6 @@ NfsManager::ManagedConnection::OnNfsConnectionError(std::exception_ptr &&e) noex
|
||||||
manager.ScheduleDelete(*this);
|
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
|
NfsManager::~NfsManager() noexcept
|
||||||
{
|
{
|
||||||
assert(!GetEventLoop().IsAlive() || GetEventLoop().IsInside());
|
assert(!GetEventLoop().IsAlive() || GetEventLoop().IsInside());
|
||||||
|
@ -92,17 +55,15 @@ NfsManager::GetConnection(const char *server, const char *export_name) noexcept
|
||||||
assert(export_name != nullptr);
|
assert(export_name != nullptr);
|
||||||
assert(GetEventLoop().IsInside());
|
assert(GetEventLoop().IsInside());
|
||||||
|
|
||||||
Map::insert_commit_data hint;
|
for (auto &c : connections)
|
||||||
auto result = connections.insert_check(LookupKey{server, export_name},
|
if (StringIsEqual(server, c.GetServer()) &&
|
||||||
Compare(), hint);
|
StringIsEqual(export_name, c.GetExportName()))
|
||||||
if (result.second) {
|
return c;
|
||||||
auto c = new ManagedConnection(*this, GetEventLoop(),
|
|
||||||
server, export_name);
|
auto c = new ManagedConnection(*this, GetEventLoop(),
|
||||||
connections.insert_commit(*c, hint);
|
server, export_name);
|
||||||
return *c;
|
connections.push_front(*c);
|
||||||
} else {
|
return *c;
|
||||||
return *result.first;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -22,24 +22,17 @@
|
||||||
|
|
||||||
#include "Connection.hxx"
|
#include "Connection.hxx"
|
||||||
#include "event/IdleEvent.hxx"
|
#include "event/IdleEvent.hxx"
|
||||||
#include "util/IntrusiveForwardList.hxx"
|
#include "util/IntrusiveList.hxx"
|
||||||
|
|
||||||
#include <boost/intrusive/set.hpp>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A manager for NFS connections. Handles multiple connections to
|
* A manager for NFS connections. Handles multiple connections to
|
||||||
* multiple NFS servers.
|
* multiple NFS servers.
|
||||||
*/
|
*/
|
||||||
class NfsManager final {
|
class NfsManager final {
|
||||||
struct LookupKey {
|
|
||||||
const char *server;
|
|
||||||
const char *export_name;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ManagedConnection final
|
class ManagedConnection final
|
||||||
: public NfsConnection,
|
: public NfsConnection,
|
||||||
public IntrusiveForwardListHook,
|
public IntrusiveListHook<>
|
||||||
public boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>> {
|
{
|
||||||
NfsManager &manager;
|
NfsManager &manager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -54,30 +47,9 @@ class NfsManager final {
|
||||||
void OnNfsConnectionError(std::exception_ptr &&e) noexcept override;
|
void OnNfsConnectionError(std::exception_ptr &&e) noexcept override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Compare {
|
using List = IntrusiveList<ManagedConnection>;
|
||||||
[[gnu::pure]]
|
|
||||||
bool operator()(const LookupKey a,
|
|
||||||
const ManagedConnection &b) const noexcept;
|
|
||||||
|
|
||||||
[[gnu::pure]]
|
List connections;
|
||||||
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<ManagedConnection,
|
|
||||||
boost::intrusive::compare<Compare>,
|
|
||||||
boost::intrusive::constant_time_size<false>> Map;
|
|
||||||
|
|
||||||
Map connections;
|
|
||||||
|
|
||||||
using List = IntrusiveForwardList<ManagedConnection>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of "garbage" connection objects. Their destruction
|
* A list of "garbage" connection objects. Their destruction
|
||||||
|
|
Loading…
Reference in New Issue