From 611ce6e7569c4ca3a0163ad1485b1861e37b1290 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 25 Jan 2017 22:58:13 +0100 Subject: [PATCH] lib/nfs/{FileReader,Glue}: pass EventLoop& Eliminate dependency on io_thread_get(). --- src/input/plugins/NfsInputPlugin.cxx | 4 +++- src/lib/nfs/FileReader.cxx | 7 +++---- src/lib/nfs/FileReader.hxx | 4 +++- src/lib/nfs/Glue.cxx | 8 +++----- src/lib/nfs/Glue.hxx | 3 ++- src/lib/nfs/Manager.hxx | 2 ++ src/storage/plugins/NfsStorage.cxx | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/input/plugins/NfsInputPlugin.cxx b/src/input/plugins/NfsInputPlugin.cxx index 470cf0282..3d7ea8e47 100644 --- a/src/input/plugins/NfsInputPlugin.cxx +++ b/src/input/plugins/NfsInputPlugin.cxx @@ -24,6 +24,7 @@ #include "lib/nfs/Glue.hxx" #include "lib/nfs/FileReader.hxx" #include "util/StringCompare.hxx" +#include "IOThread.hxx" #include @@ -49,6 +50,7 @@ public: :AsyncInputStream(_uri, _mutex, _cond, NFS_MAX_BUFFERED, NFS_RESUME_AT), + NfsFileReader(io_thread_get()), reconnect_on_resume(false), reconnecting(false) {} virtual ~NfsInputStream() { @@ -206,7 +208,7 @@ NfsInputStream::OnNfsFileError(std::exception_ptr &&e) static void input_nfs_init(const ConfigBlock &) { - nfs_init(); + nfs_init(io_thread_get()); } static void diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx index 21eadc950..69483873b 100644 --- a/src/lib/nfs/FileReader.cxx +++ b/src/lib/nfs/FileReader.cxx @@ -23,7 +23,6 @@ #include "Base.hxx" #include "Connection.hxx" #include "event/Call.hxx" -#include "IOThread.hxx" #include "util/StringCompare.hxx" #include @@ -33,8 +32,8 @@ #include #include -NfsFileReader::NfsFileReader() - :DeferredMonitor(io_thread_get()), state(State::INITIAL) +NfsFileReader::NfsFileReader(EventLoop &event_loop) + :DeferredMonitor(event_loop), state(State::INITIAL) { } @@ -86,7 +85,7 @@ NfsFileReader::CancelOrClose() void NfsFileReader::DeferClose() { - BlockingCall(io_thread_get(), [this](){ Close(); }); + BlockingCall(GetEventLoop(), [this](){ Close(); }); } void diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx index 911e62053..4a4d28930 100644 --- a/src/lib/nfs/FileReader.hxx +++ b/src/lib/nfs/FileReader.hxx @@ -64,9 +64,11 @@ class NfsFileReader : NfsLease, NfsCallback, DeferredMonitor { nfsfh *fh; public: - NfsFileReader(); + NfsFileReader(EventLoop &event_loop); ~NfsFileReader(); + using DeferredMonitor::GetEventLoop; + void Close(); void DeferClose(); diff --git a/src/lib/nfs/Glue.cxx b/src/lib/nfs/Glue.cxx index 173f4b333..be82bd855 100644 --- a/src/lib/nfs/Glue.cxx +++ b/src/lib/nfs/Glue.cxx @@ -20,7 +20,6 @@ #include "config.h" #include "Glue.hxx" #include "Manager.hxx" -#include "IOThread.hxx" #include "event/Call.hxx" #include "util/Manual.hxx" @@ -30,12 +29,12 @@ static Manual nfs_glue; static unsigned in_use; void -nfs_init() +nfs_init(EventLoop &event_loop) { if (in_use++ > 0) return; - nfs_glue.Construct(io_thread_get()); + nfs_glue.Construct(event_loop); } void @@ -46,14 +45,13 @@ nfs_finish() if (--in_use > 0) return; - BlockingCall(io_thread_get(), [](){ nfs_glue.Destruct(); }); + BlockingCall(nfs_glue->GetEventLoop(), [](){ nfs_glue.Destruct(); }); } NfsConnection & nfs_get_connection(const char *server, const char *export_name) { assert(in_use > 0); - assert(io_thread_inside()); return nfs_glue->GetConnection(server, export_name); } diff --git a/src/lib/nfs/Glue.hxx b/src/lib/nfs/Glue.hxx index 81b56ba64..d83daf37e 100644 --- a/src/lib/nfs/Glue.hxx +++ b/src/lib/nfs/Glue.hxx @@ -23,10 +23,11 @@ #include "check.h" #include "Compiler.h" +class EventLoop; class NfsConnection; void -nfs_init(); +nfs_init(EventLoop &event_loop); void nfs_finish(); diff --git a/src/lib/nfs/Manager.hxx b/src/lib/nfs/Manager.hxx index 6e9099e8f..f922ca17a 100644 --- a/src/lib/nfs/Manager.hxx +++ b/src/lib/nfs/Manager.hxx @@ -97,6 +97,8 @@ public: */ ~NfsManager(); + using IdleMonitor::GetEventLoop; + gcc_pure NfsConnection &GetConnection(const char *server, const char *export_name); diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx index acb83fc17..0e5780b61 100644 --- a/src/storage/plugins/NfsStorage.cxx +++ b/src/storage/plugins/NfsStorage.cxx @@ -74,7 +74,7 @@ public: server(std::move(_server)), export_name(std::move(_export_name)), state(State::INITIAL) { - nfs_init(); + nfs_init(_loop); } ~NfsStorage() {