aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/nfs/Manager.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-11-26 20:19:17 +0100
committerMax Kellermann <max@duempel.org>2014-11-26 20:19:17 +0100
commit737a56a0302b1030e1071c7be9add7bdca955e32 (patch)
tree93d9b6d625fa1b0ce9e8bf8d13fbc829be5178d1 /src/lib/nfs/Manager.cxx
parent12b6959ea201fea925c4376f961b8d54738292e2 (diff)
parent67cba251c8826409c82fb2ab75072dc4fca2b4dc (diff)
downloadmpd-737a56a0302b1030e1071c7be9add7bdca955e32.tar.gz
mpd-737a56a0302b1030e1071c7be9add7bdca955e32.tar.xz
mpd-737a56a0302b1030e1071c7be9add7bdca955e32.zip
Merge tag 'v0.19.5'
Diffstat (limited to 'src/lib/nfs/Manager.cxx')
-rw-r--r--src/lib/nfs/Manager.cxx30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/lib/nfs/Manager.cxx b/src/lib/nfs/Manager.cxx
index c5aecf48d..6d50cce18 100644
--- a/src/lib/nfs/Manager.cxx
+++ b/src/lib/nfs/Manager.cxx
@@ -29,8 +29,10 @@ NfsManager::ManagedConnection::OnNfsConnectionError(Error &&error)
{
FormatError(error, "NFS error on %s:%s", GetServer(), GetExportName());
- manager.connections.erase(manager.connections.iterator_to(*this));
- delete this;
+ /* defer deletion so the caller
+ (i.e. NfsConnection::OnSocketReady()) can still use this
+ object */
+ manager.ScheduleDelete(*this);
}
inline bool
@@ -59,7 +61,9 @@ NfsManager::Compare::operator()(const ManagedConnection &a,
NfsManager::~NfsManager()
{
- assert(loop.IsInside());
+ assert(GetEventLoop().IsInside());
+
+ CollectGarbage();
connections.clear_and_dispose([](ManagedConnection *c){
delete c;
@@ -71,13 +75,13 @@ NfsManager::GetConnection(const char *server, const char *export_name)
{
assert(server != nullptr);
assert(export_name != nullptr);
- assert(loop.IsInside());
+ 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, loop,
+ auto c = new ManagedConnection(*this, GetEventLoop(),
server, export_name);
connections.insert_commit(*c, hint);
return *c;
@@ -85,3 +89,19 @@ NfsManager::GetConnection(const char *server, const char *export_name)
return *result.first;
}
}
+
+void
+NfsManager::CollectGarbage()
+{
+ assert(GetEventLoop().IsInside());
+
+ garbage.clear_and_dispose([](ManagedConnection *c){
+ delete c;
+ });
+}
+
+void
+NfsManager::OnIdle()
+{
+ CollectGarbage();
+}