diff --git a/emper/Emper.hpp b/emper/Emper.hpp index fb560a5e7cfe914f88b4c1d05736f4da0caee47b..b321dc1b99da50cd564cfc13a3bd25c14b12a44c 100644 --- a/emper/Emper.hpp +++ b/emper/Emper.hpp @@ -23,14 +23,14 @@ static const bool WORKER_SLEEP = false #endif ; -enum class WorkerWakeupStrategy { one, all }; + +enum class WorkerWakeupStrategy { + one, + all, +}; + static const enum WorkerWakeupStrategy WORKER_WAKEUP_STRATEGY = -#ifdef EMPER_WORKER_WAKEUP_ALL - WorkerWakeupStrategy::all -#else - WorkerWakeupStrategy::one -#endif - ; + WorkerWakeupStrategy::EMPER_WORKER_WAKEUP_STRATEGY; static const bool LIBURCU = #ifdef EMPER_LIBURCU diff --git a/emper/Runtime.hpp b/emper/Runtime.hpp index 77afac488bdf2f0c919a6805b4404b6bf1a9dcba..726aa51939233380e5f9a6dea6ff088e522e2a0a 100644 --- a/emper/Runtime.hpp +++ b/emper/Runtime.hpp @@ -7,8 +7,8 @@ #include <atomic> // for atomic, memory_order_relaxed #include <cassert> // for assert #include <condition_variable> // for condition_variable -#include <cstddef> // for size_t #include <cstdint> // for intptr_t +#include <cstdlib> // for abort #include <functional> // for function #include <mutex> // for mutex, lock_guard, unique_lock #include <random> @@ -90,9 +90,12 @@ class Runtime : public Logger<LogSubsystem::RUNTI> { if constexpr (emper::WORKER_WAKEUP_STRATEGY == emper::WorkerWakeupStrategy::all) { sleepingWorkers.store(0, std::memory_order_relaxed); workerSleepConditionVariable.notify_all(); - } else { + } else if (emper::WORKER_WAKEUP_STRATEGY == emper::WorkerWakeupStrategy::one) { sleepingWorkers.fetch_sub(1, std::memory_order_relaxed); workerSleepConditionVariable.notify_one(); + } else { + // Unknown worker wakeup strategy. + abort(); } } diff --git a/meson.build b/meson.build index 80b41e6018cf626458793f722127a61308b6db30..6d8f5d40bf6366096784dc0a5074b763a00566ce 100644 --- a/meson.build +++ b/meson.build @@ -26,7 +26,7 @@ if option_urcu endif conf_data.set('EMPER_WORKER_SLEEP', get_option('worker_sleep')) -conf_data.set('EMPER_WORKER_WAKEUP_ALL', get_option('worker_wakeup_strategy') == 'all') +conf_data.set('EMPER_WORKER_WAKEUP_STRATEGY', get_option('worker_wakeup_strategy')) conf_data.set('EMPER_LOCKED_WS_QUEUE', get_option('locked_ws_queue')) conf_data.set('EMPER_OVERFLOW_QUEUE', get_option('overflow_queue')) conf_data.set('EMPER_LOCKED_MPSC_QUEUE', get_option('locked_mpsc_queue')) diff --git a/meson_options.txt b/meson_options.txt index 8ae9ba0eaedeeb508c966aff51a355962e312c62..99943e52a1e8e19ca2afab6f121a9b2825aa778f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -19,7 +19,7 @@ option( option( 'worker_wakeup_strategy', type: 'combo', - description: 'How many workers should be signaled onNewWork', + description: 'The strategy used to wakeup sleeping workers (only effective if worker_sleep is enabled)', choices: ['one', 'all'], value: 'one', )