diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp index 5c36d3b4183462e409bb48ed689084e4a72559c4..d8d98c58b8a542a57aec16dceae05a58f309e2d8 100644 --- a/emper/Runtime.cpp +++ b/emper/Runtime.cpp @@ -87,15 +87,13 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategyFactory& strategyFactory currentRuntime = this; } - // initialize the global and all worker IoContexts - if constexpr (emper::IO) { + // initialize the global IoContext if a completer is used + if constexpr (emper::IO && emper::IO_COMPLETER_BEHAVIOR != emper::IoCompleterBehavior::none) { // The global io_uring needs at least workerCount entries in its SQ because // for each worker's IoContext one eventfd read is prepared before the // globalCompleter is started and submits all previously prepared sqes. globalIo = new GlobalIoContext(*this, workerCount); - if constexpr (emper::IO_COMPLETER_BEHAVIOR != emper::IoCompleterBehavior::none) { - globalIo->startGlobalCompleter(); - } + globalIo->startGlobalCompleter(); if constexpr (emper::STATS) { globalIo->stats.workerId = emper::io::Stats::GLOBAL_COMPLETER_ID; @@ -175,10 +173,12 @@ Runtime::~Runtime() { delete[] threads; if constexpr (emper::IO) { - // It is safer to destroy the globalIo before the worker IoContexts - // because pointer to the worker IoContexts can outlife their objects - // in the globalCompleter - delete globalIo; + if constexpr (emper::IO_COMPLETER_BEHAVIOR != emper::IoCompleterBehavior::none) { + // It is safer to destroy the globalIo before the worker IoContexts + // because pointer to the worker IoContexts can outlife their objects + // in the globalCompleter + delete globalIo; + } for (unsigned int i = 0; i < workerCount; ++i) { delete ioContexts[i]; @@ -283,7 +283,7 @@ void Runtime::initiateTermination() { wakeupSem.notify_many(workerCount); - if constexpr (emper::IO) { + if constexpr (emper::IO && emper::IO_COMPLETER_BEHAVIOR != emper::IoCompleterBehavior::none) { globalIo->initiateTermination(); } } @@ -296,7 +296,7 @@ void Runtime::waitUntilFinished() { } } - if constexpr (emper::IO) { + if constexpr (emper::IO && emper::IO_COMPLETER_BEHAVIOR != emper::IoCompleterBehavior::none) { globalIo->waitUntilFinished(); }