Commit 1aac0b10 authored by Max Kellermann's avatar Max Kellermann

test/run_input, ...: add struct ScopeIOThread

Auto-stop the IO thread in all error handlers.
parent e5ff85b6
...@@ -1610,6 +1610,7 @@ test_run_input_LDADD = \ ...@@ -1610,6 +1610,7 @@ test_run_input_LDADD = \
libsystem.a \ libsystem.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_input_SOURCES = test/run_input.cxx \ test_run_input_SOURCES = test/run_input.cxx \
test/ScopeIOThread.hxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
...@@ -1660,6 +1661,7 @@ test_visit_archive_LDADD = \ ...@@ -1660,6 +1661,7 @@ test_visit_archive_LDADD = \
libsystem.a \ libsystem.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_visit_archive_SOURCES = test/visit_archive.cxx \ test_visit_archive_SOURCES = test/visit_archive.cxx \
test/ScopeIOThread.hxx \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/input/Open.cxx src/input/Open.cxx
...@@ -1697,6 +1699,7 @@ test_dump_text_file_LDADD = \ ...@@ -1697,6 +1699,7 @@ test_dump_text_file_LDADD = \
libutil.a \ libutil.a \
$(GLIB_LIBS) $(GLIB_LIBS)
test_dump_text_file_SOURCES = test/dump_text_file.cxx \ test_dump_text_file_SOURCES = test/dump_text_file.cxx \
test/ScopeIOThread.hxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx src/IOThread.cxx
...@@ -1718,6 +1721,7 @@ test_dump_playlist_LDADD = \ ...@@ -1718,6 +1721,7 @@ test_dump_playlist_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_dump_playlist_SOURCES = test/dump_playlist.cxx \ test_dump_playlist_SOURCES = test/dump_playlist.cxx \
test/FakeDecoderAPI.cxx test/FakeDecoderAPI.hxx \ test/FakeDecoderAPI.cxx test/FakeDecoderAPI.hxx \
test/ScopeIOThread.hxx \
$(DECODER_SRC) \ $(DECODER_SRC) \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
...@@ -1747,6 +1751,7 @@ test_run_decoder_LDADD = \ ...@@ -1747,6 +1751,7 @@ test_run_decoder_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_decoder_SOURCES = test/run_decoder.cxx \ test_run_decoder_SOURCES = test/run_decoder.cxx \
test/FakeDecoderAPI.cxx test/FakeDecoderAPI.hxx \ test/FakeDecoderAPI.cxx test/FakeDecoderAPI.hxx \
test/ScopeIOThread.hxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
...@@ -1772,6 +1777,7 @@ test_read_tags_LDADD = \ ...@@ -1772,6 +1777,7 @@ test_read_tags_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_read_tags_SOURCES = test/read_tags.cxx \ test_read_tags_SOURCES = test/read_tags.cxx \
test/FakeDecoderAPI.cxx test/FakeDecoderAPI.hxx \ test/FakeDecoderAPI.cxx test/FakeDecoderAPI.hxx \
test/ScopeIOThread.hxx \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
src/ReplayGainInfo.cxx \ src/ReplayGainInfo.cxx \
...@@ -1906,6 +1912,7 @@ test_run_output_LDADD = $(MPD_LIBS) \ ...@@ -1906,6 +1912,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_output_SOURCES = test/run_output.cxx \ test_run_output_SOURCES = test/run_output.cxx \
test/FakeReplayGainConfig.cxx \ test/FakeReplayGainConfig.cxx \
test/ScopeIOThread.hxx \
test/stdbin.h \ test/stdbin.h \
src/Log.cxx src/LogBackend.cxx \ src/Log.cxx src/LogBackend.cxx \
src/IOThread.cxx \ src/IOThread.cxx \
......
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_SCOPE_IO_THREAD_HXX
#define MPD_SCOPE_IO_THREAD_HXX
#include "IOThread.hxx"
struct ScopeIOThread {
ScopeIOThread() {
io_thread_init();
io_thread_start();
}
~ScopeIOThread() {
io_thread_deinit();
}
};
#endif
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
#include "decoder/DecoderList.hxx" #include "decoder/DecoderList.hxx"
#include "input/Init.hxx" #include "input/Init.hxx"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "playlist/PlaylistRegistry.hxx" #include "playlist/PlaylistRegistry.hxx"
#include "playlist/PlaylistPlugin.hxx" #include "playlist/PlaylistPlugin.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
...@@ -82,8 +82,7 @@ int main(int argc, char **argv) ...@@ -82,8 +82,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
LogError(error); LogError(error);
...@@ -155,7 +154,6 @@ int main(int argc, char **argv) ...@@ -155,7 +154,6 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
playlist_list_global_finish(); playlist_list_global_finish();
input_stream_global_finish(); input_stream_global_finish();
io_thread_deinit();
config_global_finish(); config_global_finish();
return 0; return 0;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "input/Init.hxx" #include "input/Init.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/TextInputStream.hxx" #include "input/TextInputStream.hxx"
...@@ -91,8 +91,7 @@ int main(int argc, char **argv) ...@@ -91,8 +91,7 @@ int main(int argc, char **argv)
config_global_init(); config_global_init();
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
archive_plugin_init_all(); archive_plugin_init_all();
...@@ -129,8 +128,6 @@ int main(int argc, char **argv) ...@@ -129,8 +128,6 @@ int main(int argc, char **argv)
archive_plugin_deinit_all(); archive_plugin_deinit_all();
#endif #endif
io_thread_deinit();
config_global_finish(); config_global_finish();
return ret; return ret;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "decoder/DecoderList.hxx" #include "decoder/DecoderList.hxx"
#include "decoder/DecoderPlugin.hxx" #include "decoder/DecoderPlugin.hxx"
#include "input/Init.hxx" #include "input/Init.hxx"
...@@ -96,8 +96,7 @@ int main(int argc, char **argv) ...@@ -96,8 +96,7 @@ int main(int argc, char **argv)
#endif #endif
#endif #endif
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
Error error; Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
...@@ -132,7 +131,6 @@ int main(int argc, char **argv) ...@@ -132,7 +131,6 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
input_stream_global_finish(); input_stream_global_finish();
io_thread_deinit();
if (!success) { if (!success) {
fprintf(stderr, "Failed to read tags\n"); fprintf(stderr, "Failed to read tags\n");
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "decoder/DecoderList.hxx" #include "decoder/DecoderList.hxx"
#include "decoder/DecoderPlugin.hxx" #include "decoder/DecoderPlugin.hxx"
#include "FakeDecoderAPI.hxx" #include "FakeDecoderAPI.hxx"
...@@ -56,8 +56,7 @@ int main(int argc, char **argv) ...@@ -56,8 +56,7 @@ int main(int argc, char **argv)
#endif #endif
#endif #endif
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
Error error; Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
...@@ -98,7 +97,6 @@ int main(int argc, char **argv) ...@@ -98,7 +97,6 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
input_stream_global_finish(); input_stream_global_finish();
io_thread_deinit();
if (!decoder.initialized) { if (!decoder.initialized) {
fprintf(stderr, "Decoding failed\n"); fprintf(stderr, "Decoding failed\n");
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/Init.hxx" #include "input/Init.hxx"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
#include "Log.hxx" #include "Log.hxx"
...@@ -123,8 +123,7 @@ int main(int argc, char **argv) ...@@ -123,8 +123,7 @@ int main(int argc, char **argv)
config_global_init(); config_global_init();
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
archive_plugin_init_all(); archive_plugin_init_all();
...@@ -160,8 +159,6 @@ int main(int argc, char **argv) ...@@ -160,8 +159,6 @@ int main(int argc, char **argv)
archive_plugin_deinit_all(); archive_plugin_deinit_all();
#endif #endif
io_thread_deinit();
config_global_finish(); config_global_finish();
return ret; return ret;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "Idle.hxx" #include "Idle.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "AudioParser.hxx" #include "AudioParser.hxx"
#include "pcm/PcmConvert.hxx" #include "pcm/PcmConvert.hxx"
...@@ -179,8 +179,7 @@ int main(int argc, char **argv) ...@@ -179,8 +179,7 @@ int main(int argc, char **argv)
EventLoop event_loop; EventLoop event_loop;
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
/* initialize the audio output */ /* initialize the audio output */
...@@ -205,8 +204,6 @@ int main(int argc, char **argv) ...@@ -205,8 +204,6 @@ int main(int argc, char **argv)
audio_output_free(ao); audio_output_free(ao);
io_thread_deinit();
config_global_finish(); config_global_finish();
return success ? EXIT_SUCCESS : EXIT_FAILURE; return success ? EXIT_SUCCESS : EXIT_FAILURE;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "stdbin.h" #include "stdbin.h"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
#include "IOThread.hxx" #include "ScopeIOThread.hxx"
#include "input/Init.hxx" #include "input/Init.hxx"
#include "archive/ArchiveList.hxx" #include "archive/ArchiveList.hxx"
#include "archive/ArchivePlugin.hxx" #include "archive/ArchivePlugin.hxx"
...@@ -65,8 +65,7 @@ main(int argc, char **argv) ...@@ -65,8 +65,7 @@ main(int argc, char **argv)
config_global_init(); config_global_init();
io_thread_init(); const ScopeIOThread io_thread;
io_thread_start();
archive_plugin_init_all(); archive_plugin_init_all();
...@@ -101,8 +100,6 @@ main(int argc, char **argv) ...@@ -101,8 +100,6 @@ main(int argc, char **argv)
archive_plugin_deinit_all(); archive_plugin_deinit_all();
io_thread_deinit();
config_global_finish(); config_global_finish();
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment