IOThread: move EventThread instance into struct Instance

Eliminate global variables.
This commit is contained in:
Max Kellermann 2017-02-10 21:46:07 +01:00
parent d1456ae039
commit 5e081de14a
8 changed files with 20 additions and 29 deletions

View File

@ -129,7 +129,6 @@ libmpd_a_SOURCES = \
src/Log.cxx src/Log.hxx src/LogV.hxx \ src/Log.cxx src/Log.hxx src/LogV.hxx \
src/LogLevel.hxx \ src/LogLevel.hxx \
src/ls.cxx src/ls.hxx \ src/ls.cxx src/ls.hxx \
src/IOThread.cxx src/IOThread.hxx \
src/Instance.cxx src/Instance.hxx \ src/Instance.cxx src/Instance.hxx \
src/win32/Win32Main.cxx \ src/win32/Win32Main.cxx \
src/MixRampInfo.hxx \ src/MixRampInfo.hxx \

View File

@ -51,11 +51,3 @@ io_thread_deinit(void)
delete io_thread; delete io_thread;
io_thread = nullptr; io_thread = nullptr;
} }
EventLoop &
io_thread_get()
{
assert(io_thread != nullptr);
return io_thread->GetEventLoop();
}

View File

@ -33,8 +33,4 @@ io_thread_start();
void void
io_thread_deinit(); io_thread_deinit();
gcc_const
EventLoop &
io_thread_get();
#endif #endif

View File

@ -22,6 +22,7 @@
#include "check.h" #include "check.h"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "event/Thread.hxx"
#include "event/MaskMonitor.hxx" #include "event/MaskMonitor.hxx"
#include "Compiler.h" #include "Compiler.h"
@ -64,6 +65,8 @@ struct Instance final
public NeighborListener public NeighborListener
#endif #endif
{ {
EventThread io_thread;
MaskMonitor idle_monitor; MaskMonitor idle_monitor;
#ifdef ENABLE_NEIGHBOR_PLUGINS #ifdef ENABLE_NEIGHBOR_PLUGINS

View File

@ -39,7 +39,6 @@
#include "LogInit.hxx" #include "LogInit.hxx"
#include "input/Init.hxx" #include "input/Init.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "IOThread.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "fs/Config.hxx" #include "fs/Config.hxx"
#include "playlist/PlaylistRegistry.hxx" #include "playlist/PlaylistRegistry.hxx"
@ -161,9 +160,9 @@ glue_mapper_init()
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
static void static void
InitStorage() InitStorage(EventLoop &event_loop)
{ {
Storage *storage = CreateConfiguredStorage(io_thread_get()); Storage *storage = CreateConfiguredStorage(event_loop);
if (storage == nullptr) if (storage == nullptr)
return; return;
@ -186,7 +185,7 @@ glue_db_init_and_load(void)
return true; return true;
if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) { if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
InitStorage(); InitStorage(instance->io_thread.GetEventLoop());
if (instance->storage == nullptr) { if (instance->storage == nullptr) {
delete instance->database; delete instance->database;
@ -421,7 +420,6 @@ try {
IcuInit(); IcuInit();
winsock_init(); winsock_init();
io_thread_init();
config_global_init(); config_global_init();
#ifdef ANDROID #ifdef ANDROID
@ -453,7 +451,8 @@ try {
#ifdef ENABLE_NEIGHBOR_PLUGINS #ifdef ENABLE_NEIGHBOR_PLUGINS
instance->neighbors = new NeighborGlue(); instance->neighbors = new NeighborGlue();
instance->neighbors->Init(io_thread_get(), *instance); instance->neighbors->Init(instance->io_thread.GetEventLoop(),
*instance);
if (instance->neighbors->IsEmpty()) { if (instance->neighbors->IsEmpty()) {
delete instance->neighbors; delete instance->neighbors;
@ -519,13 +518,13 @@ try {
command_init(); command_init();
instance->partition->outputs.Configure(io_thread_get(), instance->partition->outputs.Configure(instance->io_thread.GetEventLoop(),
config.replay_gain, config.replay_gain,
instance->partition->pc); instance->partition->pc);
instance->partition->UpdateEffectiveReplayGainMode(); instance->partition->UpdateEffectiveReplayGainMode();
client_manager_init(); client_manager_init();
input_stream_global_init(io_thread_get()); input_stream_global_init(instance->io_thread.GetEventLoop());
playlist_list_global_init(); playlist_list_global_init();
#ifdef ENABLE_DAEMON #ifdef ENABLE_DAEMON
@ -538,7 +537,7 @@ try {
SignalHandlersInit(instance->event_loop); SignalHandlersInit(instance->event_loop);
#endif #endif
io_thread_start(); instance->io_thread.Start();
#ifdef ENABLE_NEIGHBOR_PLUGINS #ifdef ENABLE_NEIGHBOR_PLUGINS
if (instance->neighbors != nullptr) if (instance->neighbors != nullptr)
@ -660,7 +659,7 @@ try {
archive_plugin_deinit_all(); archive_plugin_deinit_all();
#endif #endif
config_global_finish(); config_global_finish();
io_thread_deinit(); instance->io_thread.Stop();
#ifndef ANDROID #ifndef ANDROID
SignalHandlersFinish(); SignalHandlersFinish();
#endif #endif

View File

@ -117,7 +117,8 @@ handle_listfiles(Client &client, Request args, Response &r)
case LocatedUri::Type::ABSOLUTE: case LocatedUri::Type::ABSOLUTE:
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
/* use storage plugin to list remote directory */ /* use storage plugin to list remote directory */
return handle_listfiles_storage(r, located_uri.canonical_uri); return handle_listfiles_storage(client, r,
located_uri.canonical_uri);
#else #else
r.Error(ACK_ERROR_NO_EXIST, "No database"); r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR; return CommandResult::ERROR;

View File

@ -36,7 +36,6 @@
#include "db/plugins/simple/SimpleDatabasePlugin.hxx" #include "db/plugins/simple/SimpleDatabasePlugin.hxx"
#include "db/update/Service.hxx" #include "db/update/Service.hxx"
#include "TimePrint.hxx" #include "TimePrint.hxx"
#include "IOThread.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include <memory> #include <memory>
@ -107,9 +106,10 @@ handle_listfiles_storage(Response &r, Storage &storage, const char *uri)
} }
CommandResult CommandResult
handle_listfiles_storage(Response &r, const char *uri) handle_listfiles_storage(Client &client, Response &r, const char *uri)
{ {
std::unique_ptr<Storage> storage(CreateStorageURI(io_thread_get(), uri)); auto &event_loop = client.partition.instance.io_thread.GetEventLoop();
std::unique_ptr<Storage> storage(CreateStorageURI(event_loop, uri));
if (storage == nullptr) { if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI"); r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
return CommandResult::ERROR; return CommandResult::ERROR;
@ -195,7 +195,8 @@ handle_mount(Client &client, Request args, Response &r)
return CommandResult::ERROR; return CommandResult::ERROR;
} }
Storage *storage = CreateStorageURI(io_thread_get(), remote_uri); auto &event_loop = client.partition.instance.io_thread.GetEventLoop();
Storage *storage = CreateStorageURI(event_loop, remote_uri);
if (storage == nullptr) { if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI"); r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
return CommandResult::ERROR; return CommandResult::ERROR;

View File

@ -31,7 +31,7 @@ CommandResult
handle_listfiles_storage(Response &r, Storage &storage, const char *uri); handle_listfiles_storage(Response &r, Storage &storage, const char *uri);
CommandResult CommandResult
handle_listfiles_storage(Response &r, const char *uri); handle_listfiles_storage(Client &client, Response &r, const char *uri);
CommandResult CommandResult
handle_listmounts(Client &client, Request request, Response &response); handle_listmounts(Client &client, Request request, Response &response);