mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-07 11:47:45 +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 #####################################################
|
# General server settings #####################################################
|
||||||
#
|
#
|
||||||
[server]
|
[server]
|
||||||
# Number of threads to use
|
# Number of additional worker threads to use
|
||||||
# For values <= 0 the number of threads will be 2 (on single and dual cores)
|
# - For values < 0 the number of threads will be 1 (on single cores),
|
||||||
# or 4 (for quad and more 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
|
#threads = -1
|
||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
@ -267,16 +267,21 @@ int main(int argc, char* argv[])
|
||||||
std::unique_ptr<StreamServer> streamServer(new StreamServer(io_context, settings));
|
std::unique_ptr<StreamServer> streamServer(new StreamServer(io_context, settings));
|
||||||
streamServer->start();
|
streamServer->start();
|
||||||
|
|
||||||
if (num_threads <= 0)
|
if (num_threads < 0)
|
||||||
num_threads = std::max(2, std::min(4, static_cast<int>(std::thread::hardware_concurrency())));
|
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";
|
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;
|
std::vector<std::thread> threads;
|
||||||
for (int n = 0; n < num_threads; ++n)
|
for (int n = 0; n < num_threads; ++n)
|
||||||
threads.emplace_back([&] { io_context.run(); });
|
threads.emplace_back([&] { io_context.run(); });
|
||||||
|
|
||||||
auto sig = install_signal_handler({SIGHUP, SIGTERM, SIGINT}).get();
|
io_context.run();
|
||||||
SLOG(INFO) << "Received signal " << sig << ": " << strsignal(sig) << "\n";
|
|
||||||
io_context.stop();
|
|
||||||
for (auto& t : threads)
|
for (auto& t : threads)
|
||||||
t.join();
|
t.join();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue