mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-18 19:46:14 +02:00
Server can run on the main thread only
This commit is contained in:
parent
210ab80f71
commit
b5551d9451
2 changed files with 16 additions and 8 deletions
|
@ -18,9 +18,12 @@
|
|||
# General server settings #####################################################
|
||||
#
|
||||
[server]
|
||||
# Number of threads to use
|
||||
# For values <= 0 the number of threads will be 2 (on single and dual cores)
|
||||
# or 4 (for quad and more cores)
|
||||
# Number of additional worker threads to use
|
||||
# - For values < 0 the number of threads will be 1 (on single cores),
|
||||
# 2 (on dual cores) or 4 (for quad and more cores)
|
||||
# - 0 will utilize just the processes main thread and might cause audio drops
|
||||
# in case there are a couple of longer running tasks, such as encoding
|
||||
# multiple audio streams
|
||||
#threads = -1
|
||||
#
|
||||
###############################################################################
|
||||
|
|
|
@ -267,16 +267,21 @@ int main(int argc, char* argv[])
|
|||
std::unique_ptr<StreamServer> streamServer(new StreamServer(io_context, settings));
|
||||
streamServer->start();
|
||||
|
||||
if (num_threads <= 0)
|
||||
num_threads = std::max(2, std::min(4, static_cast<int>(std::thread::hardware_concurrency())));
|
||||
if (num_threads < 0)
|
||||
num_threads = std::max(1, std::min(4, static_cast<int>(std::thread::hardware_concurrency())));
|
||||
LOG(INFO) << "number of threads: " << num_threads << ", hw threads: " << std::thread::hardware_concurrency() << "\n";
|
||||
|
||||
auto sig = install_signal_handler({SIGHUP, SIGTERM, SIGINT}, [&io_context](int signal, const std::string& name) {
|
||||
SLOG(INFO) << "Received signal " << signal << ": " << name << "\n";
|
||||
io_context.stop();
|
||||
});
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for (int n = 0; n < num_threads; ++n)
|
||||
threads.emplace_back([&] { io_context.run(); });
|
||||
|
||||
auto sig = install_signal_handler({SIGHUP, SIGTERM, SIGINT}).get();
|
||||
SLOG(INFO) << "Received signal " << sig << ": " << strsignal(sig) << "\n";
|
||||
io_context.stop();
|
||||
io_context.run();
|
||||
|
||||
for (auto& t : threads)
|
||||
t.join();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue