configurable number of threads

This commit is contained in:
badaix 2019-11-01 11:41:20 +01:00
parent c58f66a87a
commit 4022e59018

View file

@ -80,6 +80,8 @@ int main(int argc, char* argv[])
auto streamValue = conf.add<Value<string>>(
"s", "stream.stream", "URI of the PCM input stream.\nFormat: TYPE://host/path?name=NAME\n[&codec=CODEC]\n[&sampleformat=SAMPLEFORMAT]", pcmStream,
&pcmStream);
size_t num_threads = 2;
conf.add<Value<size_t>>("", "stream.threads", "number of streaming threads", num_threads, &num_threads);
conf.add<Value<string>>("", "stream.sampleformat", "Default sample format", settings.stream.sampleFormat, &settings.stream.sampleFormat);
conf.add<Value<string>>("c", "stream.codec", "Default transport codec\n(flac|ogg|pcm)[:options]\nType codec:? to get codec specific options",
@ -261,12 +263,16 @@ int main(int argc, char* argv[])
std::unique_ptr<StreamServer> streamServer(new StreamServer(io_context, settings));
streamServer->start();
std::thread t([&] { io_context.run(); });
LOG(DEBUG) << "number of threads: " << num_threads << ", hw threads: " << std::thread::hardware_concurrency() << "\n";
std::vector<std::thread> threads;
for (auto 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();
t.join();
for (auto& t : threads)
t.join();
LOG(INFO) << "Stopping streamServer" << endl;
streamServer->stop();