IOThread: move EventThread instance into struct Instance
Eliminate global variables.
This commit is contained in:
parent
d1456ae039
commit
5e081de14a
@ -129,7 +129,6 @@ libmpd_a_SOURCES = \
|
||||
src/Log.cxx src/Log.hxx src/LogV.hxx \
|
||||
src/LogLevel.hxx \
|
||||
src/ls.cxx src/ls.hxx \
|
||||
src/IOThread.cxx src/IOThread.hxx \
|
||||
src/Instance.cxx src/Instance.hxx \
|
||||
src/win32/Win32Main.cxx \
|
||||
src/MixRampInfo.hxx \
|
||||
|
@ -51,11 +51,3 @@ io_thread_deinit(void)
|
||||
delete io_thread;
|
||||
io_thread = nullptr;
|
||||
}
|
||||
|
||||
EventLoop &
|
||||
io_thread_get()
|
||||
{
|
||||
assert(io_thread != nullptr);
|
||||
|
||||
return io_thread->GetEventLoop();
|
||||
}
|
||||
|
@ -33,8 +33,4 @@ io_thread_start();
|
||||
void
|
||||
io_thread_deinit();
|
||||
|
||||
gcc_const
|
||||
EventLoop &
|
||||
io_thread_get();
|
||||
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "check.h"
|
||||
#include "event/Loop.hxx"
|
||||
#include "event/Thread.hxx"
|
||||
#include "event/MaskMonitor.hxx"
|
||||
#include "Compiler.h"
|
||||
|
||||
@ -64,6 +65,8 @@ struct Instance final
|
||||
public NeighborListener
|
||||
#endif
|
||||
{
|
||||
EventThread io_thread;
|
||||
|
||||
MaskMonitor idle_monitor;
|
||||
|
||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||
|
19
src/Main.cxx
19
src/Main.cxx
@ -39,7 +39,6 @@
|
||||
#include "LogInit.hxx"
|
||||
#include "input/Init.hxx"
|
||||
#include "event/Loop.hxx"
|
||||
#include "IOThread.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "fs/Config.hxx"
|
||||
#include "playlist/PlaylistRegistry.hxx"
|
||||
@ -161,9 +160,9 @@ glue_mapper_init()
|
||||
#ifdef ENABLE_DATABASE
|
||||
|
||||
static void
|
||||
InitStorage()
|
||||
InitStorage(EventLoop &event_loop)
|
||||
{
|
||||
Storage *storage = CreateConfiguredStorage(io_thread_get());
|
||||
Storage *storage = CreateConfiguredStorage(event_loop);
|
||||
if (storage == nullptr)
|
||||
return;
|
||||
|
||||
@ -186,7 +185,7 @@ glue_db_init_and_load(void)
|
||||
return true;
|
||||
|
||||
if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
|
||||
InitStorage();
|
||||
InitStorage(instance->io_thread.GetEventLoop());
|
||||
|
||||
if (instance->storage == nullptr) {
|
||||
delete instance->database;
|
||||
@ -421,7 +420,6 @@ try {
|
||||
IcuInit();
|
||||
|
||||
winsock_init();
|
||||
io_thread_init();
|
||||
config_global_init();
|
||||
|
||||
#ifdef ANDROID
|
||||
@ -453,7 +451,8 @@ try {
|
||||
|
||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||
instance->neighbors = new NeighborGlue();
|
||||
instance->neighbors->Init(io_thread_get(), *instance);
|
||||
instance->neighbors->Init(instance->io_thread.GetEventLoop(),
|
||||
*instance);
|
||||
|
||||
if (instance->neighbors->IsEmpty()) {
|
||||
delete instance->neighbors;
|
||||
@ -519,13 +518,13 @@ try {
|
||||
|
||||
command_init();
|
||||
|
||||
instance->partition->outputs.Configure(io_thread_get(),
|
||||
instance->partition->outputs.Configure(instance->io_thread.GetEventLoop(),
|
||||
config.replay_gain,
|
||||
instance->partition->pc);
|
||||
instance->partition->UpdateEffectiveReplayGainMode();
|
||||
|
||||
client_manager_init();
|
||||
input_stream_global_init(io_thread_get());
|
||||
input_stream_global_init(instance->io_thread.GetEventLoop());
|
||||
playlist_list_global_init();
|
||||
|
||||
#ifdef ENABLE_DAEMON
|
||||
@ -538,7 +537,7 @@ try {
|
||||
SignalHandlersInit(instance->event_loop);
|
||||
#endif
|
||||
|
||||
io_thread_start();
|
||||
instance->io_thread.Start();
|
||||
|
||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||
if (instance->neighbors != nullptr)
|
||||
@ -660,7 +659,7 @@ try {
|
||||
archive_plugin_deinit_all();
|
||||
#endif
|
||||
config_global_finish();
|
||||
io_thread_deinit();
|
||||
instance->io_thread.Stop();
|
||||
#ifndef ANDROID
|
||||
SignalHandlersFinish();
|
||||
#endif
|
||||
|
@ -117,7 +117,8 @@ handle_listfiles(Client &client, Request args, Response &r)
|
||||
case LocatedUri::Type::ABSOLUTE:
|
||||
#ifdef ENABLE_DATABASE
|
||||
/* 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
|
||||
r.Error(ACK_ERROR_NO_EXIST, "No database");
|
||||
return CommandResult::ERROR;
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "db/plugins/simple/SimpleDatabasePlugin.hxx"
|
||||
#include "db/update/Service.hxx"
|
||||
#include "TimePrint.hxx"
|
||||
#include "IOThread.hxx"
|
||||
#include "Idle.hxx"
|
||||
|
||||
#include <memory>
|
||||
@ -107,9 +106,10 @@ handle_listfiles_storage(Response &r, Storage &storage, const char *uri)
|
||||
}
|
||||
|
||||
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) {
|
||||
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
|
||||
return CommandResult::ERROR;
|
||||
@ -195,7 +195,8 @@ handle_mount(Client &client, Request args, Response &r)
|
||||
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) {
|
||||
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
|
||||
return CommandResult::ERROR;
|
||||
|
@ -31,7 +31,7 @@ CommandResult
|
||||
handle_listfiles_storage(Response &r, Storage &storage, const char *uri);
|
||||
|
||||
CommandResult
|
||||
handle_listfiles_storage(Response &r, const char *uri);
|
||||
handle_listfiles_storage(Client &client, Response &r, const char *uri);
|
||||
|
||||
CommandResult
|
||||
handle_listmounts(Client &client, Request request, Response &response);
|
||||
|
Loading…
Reference in New Issue
Block a user