From 0da9832c466867279d15b1d29a14c0569b8bc732 Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fischer@muhq.space>
Date: Sun, 24 Apr 2022 11:59:32 +0200
Subject: [PATCH] make sleep semaphore threshold configurable for mazstab

---
 emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp | 7 ++++++-
 meson.build                                           | 1 +
 meson_options.txt                                     | 7 +++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp b/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp
index 40b4b11c..176fe412 100644
--- a/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp
+++ b/emper/sleep_strategy/SemaphoreWorkerSleepStrategy.hpp
@@ -160,7 +160,12 @@ class AbstractSemaphoreWorkerSleepStrategy
 		 * reviewed and potentially changed to '-1'.
 		 * skipWakeupThreshold = 0;
 		 */
-		const typename Sem::CounterType skipWakeupThreshold = workerCount;
+		typename Sem::CounterType skipWakeupThreshold;
+		if constexpr (callerEnvironment == CallerEnvironment::ANYWHERE) {
+			skipWakeupThreshold = workerCount;
+		} else {
+			skipWakeupThreshold = EMPER_SLEEP_SEM_THRESHOLD;
+		}
 
 		auto semValue = wakeupSem.getValue();
 		return semValue <= skipWakeupThreshold;
diff --git a/meson.build b/meson.build
index 36c35531..e97c3196 100644
--- a/meson.build
+++ b/meson.build
@@ -89,6 +89,7 @@ else
 endif
 
 
+conf_data.set('EMPER_SLEEP_SEM_THRESHOLD', get_option('sleep_sem_threshold'))
 conf_data.set('EMPER_WORKER_SLEEP', get_option('worker_sleep'))
 conf_data.set('EMPER_WORKER_WAKEUP_STRATEGY', get_option('worker_wakeup_strategy'))
 conf_data.set('EMPER_WORKER_IGNORE_WAKEUP_HINT', get_option('worker_ignore_wakeup_hint'))
diff --git a/meson_options.txt b/meson_options.txt
index 8ba72e61..3ec221d6 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,10 @@
+option(
+  'sleep_sem_threshold',
+  type: 'combo',
+  choices: ['0', 'workerCount'],
+  value: 'workerCount',
+  description: 'Threshold skipping the notification'
+)
 option(
   'use_bundled_deps',
   type: 'combo',
-- 
GitLab