From 37c0b51f0a4564a6c3aefcf5696d681e4f34d78e Mon Sep 17 00:00:00 2001
From: Alexis Nicolin <alexisnicolin@gmail.com>
Date: Wed, 21 Nov 2018 14:33:07 +0100
Subject: [PATCH] Fixed RealTimeLogger scheduler and priority

---
 src/debug/real-time-logger.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/debug/real-time-logger.cpp b/src/debug/real-time-logger.cpp
index 9e625bf..97ad576 100644
--- a/src/debug/real-time-logger.cpp
+++ b/src/debug/real-time-logger.cpp
@@ -94,6 +94,19 @@ namespace dynamicgraph
 
     void spin (RealTimeLogger* logger)
     {
+      // Change the thread's scheduler from real-time to normal and reduce its priority
+      int threadPolicy;
+      struct sched_param threadParam;
+      if (pthread_getschedparam (pthread_self(), &threadPolicy, &threadParam) == 0)
+      {
+        threadPolicy = SCHED_OTHER;
+        threadParam.sched_priority -= 5;
+        if (threadParam.sched_priority < sched_get_priority_min (threadPolicy))
+          threadParam.sched_priority = sched_get_priority_min (threadPolicy);
+         
+        pthread_setschedparam (pthread_self(), threadPolicy, &threadParam);
+      } 
+
       while (!requestShutdown_ || !logger->empty())
       {
         // If the logger did not write anything, it means the buffer is empty.
-- 
GitLab