From b49cfe96f406bf0b750b7a1ea73609905d606335 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Thu, 30 Jan 2025 10:53:20 +0100
Subject: [PATCH] event/Thread: start the thread in the constructor

This is the proper fix for the e309941646e0ff1b6 regression; see
commit abc84206977744f30f528f2ef27d87220266276d
---
 src/Main.cxx            | 3 ---
 src/event/Thread.hxx    | 6 ++++--
 test/DumpDatabase.cxx   | 6 ------
 test/DumpOgg.cxx        | 1 -
 test/RunChromaprint.cxx | 2 --
 test/dump_playlist.cxx  | 1 -
 test/dump_text_file.cxx | 1 -
 test/read_tags.cxx      | 1 -
 test/run_decoder.cxx    | 1 -
 test/run_input.cxx      | 1 -
 test/run_output.cxx     | 1 -
 test/run_storage.cxx    | 1 -
 test/visit_archive.cxx  | 1 -
 13 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/src/Main.cxx b/src/Main.cxx
index 71d9a2b4a..d37a6e3e2 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -329,9 +329,6 @@ MainConfigured(const CommandLineOptions &options,
 	Instance instance;
 	global_instance = &instance;
 
-	instance.io_thread.Start();
-	instance.rtio_thread.Start();
-
 #ifdef ENABLE_NEIGHBOR_PLUGINS
 	instance.neighbors = std::make_unique<NeighborGlue>();
 	instance.neighbors->Init(raw_config,
diff --git a/src/event/Thread.hxx b/src/event/Thread.hxx
index a13acb54b..6ea71d112 100644
--- a/src/event/Thread.hxx
+++ b/src/event/Thread.hxx
@@ -20,7 +20,9 @@ class EventThread final {
 public:
 	explicit EventThread(bool _realtime=false)
 		:event_loop(ThreadId::Null()), thread(BIND_THIS_METHOD(Run)),
-		 realtime(_realtime) {}
+		 realtime(_realtime) {
+		Start();
+	}
 
 	~EventThread() noexcept {
 		Stop();
@@ -30,11 +32,11 @@ public:
 		return event_loop;
 	}
 
+private:
 	void Start();
 
 	void Stop() noexcept;
 
-private:
 	void Run() noexcept;
 };
 
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index ec9e57a04..cff3079ca 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -28,12 +28,6 @@ class GlobalInit {
 	EventThread io_thread;
 
 public:
-	GlobalInit() {
-		io_thread.Start();
-	}
-
-	~GlobalInit() = default;
-
 	EventLoop &GetEventLoop() {
 		return io_thread.GetEventLoop();
 	}
diff --git a/test/DumpOgg.cxx b/test/DumpOgg.cxx
index 12679c6bc..d5b982342 100644
--- a/test/DumpOgg.cxx
+++ b/test/DumpOgg.cxx
@@ -24,7 +24,6 @@ try {
 	const char *path = argv[1];
 
 	EventThread io_thread;
-	io_thread.Start();
 
 	const ScopeInputPluginsInit input_plugins_init(ConfigData(),
 						       io_thread.GetEventLoop());
diff --git a/test/RunChromaprint.cxx b/test/RunChromaprint.cxx
index 03d5a8c5d..3560fd5a0 100644
--- a/test/RunChromaprint.cxx
+++ b/test/RunChromaprint.cxx
@@ -84,8 +84,6 @@ public:
 		 input_plugins_init(config, io_thread.GetEventLoop()),
 		 decoder_plugins_init(config)
 	{
-		io_thread.Start();
-
 		pcm_convert_global_init(config);
 	}
 };
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index 883ac2878..d03d2f0d8 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -47,7 +47,6 @@ try {
 	const auto config = AutoLoadConfigFile(config_path);
 
 	EventThread io_thread;
-	io_thread.Start();
 
 	const ScopeInputPluginsInit input_plugins_init(config, io_thread.GetEventLoop());
 	const ScopePlaylistPluginsInit playlist_plugins_init(config);
diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx
index e2b9aad02..6f3cec9b7 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -34,7 +34,6 @@ public:
 	explicit GlobalInit(Path config_path)
 		:config(AutoLoadConfigFile(config_path))
 	{
-		io_thread.Start();
 	}
 };
 
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index 35b52a5c2..0734d21cb 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -86,7 +86,6 @@ try {
 	const char *path = argv[2];
 
 	EventThread io_thread;
-	io_thread.Start();
 
 	const ScopeInputPluginsInit input_plugins_init(ConfigData(),
 						       io_thread.GetEventLoop());
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index 64d57bd7b..83a0cb3ff 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -91,7 +91,6 @@ public:
 		 input_plugins_init(config, io_thread.GetEventLoop()),
 		 decoder_plugins_init(config)
 	{
-		io_thread.Start();
 	}
 };
 
diff --git a/test/run_input.cxx b/test/run_input.cxx
index caa20d7a8..3a924bd79 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -130,7 +130,6 @@ public:
 	explicit GlobalInit(Path config_path)
 		:config(AutoLoadConfigFile(config_path))
 	{
-		io_thread.Start();
 	}
 };
 
diff --git a/test/run_output.cxx b/test/run_output.cxx
index d8e2fb605..b45b248c6 100644
--- a/test/run_output.cxx
+++ b/test/run_output.cxx
@@ -158,7 +158,6 @@ try {
 	const auto config = AutoLoadConfigFile(c.config_path);
 
 	EventThread io_thread;
-	io_thread.Start();
 
 	/* initialize the audio output */
 
diff --git a/test/run_storage.cxx b/test/run_storage.cxx
index 4ef2c8179..b6ebef32a 100644
--- a/test/run_storage.cxx
+++ b/test/run_storage.cxx
@@ -114,7 +114,6 @@ public:
 	GlobalInit(Path config_path)
 		:config(AutoLoadConfigFile(config_path))
 	{
-		io_thread.Start();
 	}
 
 	EventLoop &GetEventLoop() noexcept {
diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx
index e4167a882..96e57f44f 100644
--- a/test/visit_archive.cxx
+++ b/test/visit_archive.cxx
@@ -35,7 +35,6 @@ public:
 	explicit GlobalInit(Path config_path)
 		:config(AutoLoadConfigFile(config_path))
 	{
-		io_thread.Start();
 	}
 };