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 "util/DeleteDisposer.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/StringAPI.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -22,24 +22,17 @@
|
|||
|
||||
#include "Connection.hxx"
|
||||
#include "event/IdleEvent.hxx"
|
||||
#include "util/IntrusiveForwardList.hxx"
|
||||
|
||||
#include <boost/intrusive/set.hpp>
|
||||
#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<boost::intrusive::link_mode<boost::intrusive::normal_link>> {
|
||||
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<ManagedConnection>;
|
||||
|
||||
[[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<ManagedConnection,
|
||||
boost::intrusive::compare<Compare>,
|
||||
boost::intrusive::constant_time_size<false>> Map;
|
||||
|
||||
Map connections;
|
||||
|
||||
using List = IntrusiveForwardList<ManagedConnection>;
|
||||
List connections;
|
||||
|
||||
/**
|
||||
* A list of "garbage" connection objects. Their destruction
|
||||
|
|
Loading…
Reference in New Issue