From 1421a98d9b59a076138c6f4dacb0dbd04bb1a7f8 Mon Sep 17 00:00:00 2001
From: Terraneo Federico <fede.tft@miosix.org>
Date: Sat, 29 Apr 2023 20:17:00 +0200
Subject: [PATCH] Use pauseKernel in condition variable where appropriate

---
 miosix/kernel/sync.cpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/miosix/kernel/sync.cpp b/miosix/kernel/sync.cpp
index b7cc79b9..fae7ec0e 100644
--- a/miosix/kernel/sync.cpp
+++ b/miosix/kernel/sync.cpp
@@ -414,7 +414,8 @@ TimedWaitResult ConditionVariable::timedWait(pthread_mutex_t *m, long long absTi
 bool ConditionVariable::doSignal()
 {
     bool hppw=false;
-    FastInterruptDisableLock lock; //TODO: Can we pause kernel here?
+    // We could just pause the kernel but it's faster to disable interrupts
+    FastInterruptDisableLock dLock;
     if(condList.empty()) return false;
     Thread *t=condList.front()->thread;
     condList.pop_front();
@@ -427,13 +428,15 @@ bool ConditionVariable::doSignal()
 bool ConditionVariable::doBroadcast()
 {
     bool hppw=false;
-    FastInterruptDisableLock lock; //TODO: Can we pause kernel here?
+    // Disabling interrupts would be faster but pausing kernel is an opportunity
+    // to reduce interrupt latency
+    PauseKernelLock dLock;
     while(!condList.empty())
     {
         Thread *t=condList.front()->thread;
         condList.pop_front();
-        t->IRQwakeup();
-        if(t->IRQgetPriority()>Thread::IRQgetCurrentThread()->IRQgetPriority())
+        t->PKwakeup();
+        if(t->getPriority()>Thread::PKgetCurrentThread()->getPriority())
             hppw=true;
     }
     return hppw;
-- 
GitLab