From 45b4dec42d0aee1e926899ccbcdaddee4b196582 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Tue, 12 Feb 2019 17:28:37 +0100
Subject: [PATCH] use exceptions instead of return codes for error handling

---
 common/include/villas/kernel/rt.hpp | 12 ++++++------
 common/lib/kernel/rt.cpp            | 23 +++++++----------------
 2 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/common/include/villas/kernel/rt.hpp b/common/include/villas/kernel/rt.hpp
index 5ac32bf87..506d69573 100644
--- a/common/include/villas/kernel/rt.hpp
+++ b/common/include/villas/kernel/rt.hpp
@@ -32,20 +32,20 @@ namespace villas {
 namespace kernel {
 namespace rt {
 
-int init(int priority, int affinity);
+void init(int priority, int affinity);
 
-int setAffinity(int affinity);
+void setAffinity(int affinity);
 
-int setPriority(int priority);
+void setPriority(int priority);
 
 /** Checks for realtime (PREEMPT_RT) patched kernel.
  *
  * See https://rt.wiki.kernel.org
  *
- * @retval 0 Kernel is patched.
- * @reval <>0 Kernel is not patched.
+ * @retval true Kernel is patched.
+ * @retval false Kernel is not patched.
  */
-int isPreemptible();
+bool isPreemptible();
 
 } // namespace villas
 } // namespace kernel
diff --git a/common/lib/kernel/rt.cpp b/common/lib/kernel/rt.cpp
index 773509324..4cf0f1618 100644
--- a/common/lib/kernel/rt.cpp
+++ b/common/lib/kernel/rt.cpp
@@ -22,7 +22,6 @@
 
 #include <sched.h>
 #include <unistd.h>
-#include <sys/mman.h>
 
 #include <villas/log.hpp>
 #include <villas/cpuset.hpp>
@@ -42,7 +41,7 @@ namespace villas {
 namespace kernel {
 namespace rt {
 
-int init(int priority, int affinity)
+void init(int priority, int affinity)
 {
 	Logger logger = logging.get("kernel:rt");
 
@@ -53,7 +52,7 @@ int init(int priority, int affinity)
 
 	/* Use FIFO scheduler with real time priority */
 	is_rt = isPreemptible();
-	if (is_rt)
+	if (!is_rt)
 		logger->warn("We recommend to use an PREEMPT_RT patched kernel!");
 
 	if (priority)
@@ -65,20 +64,16 @@ int init(int priority, int affinity)
 		setAffinity(affinity);
 	else
 		logger->warn("You might want to use the 'affinity' setting to pin " PROJECT_NAME " to dedicate CPU cores");
-
-	lockMemory();
 #else
 	logger->warn("This platform is not optimized for real-time execution");
+
 	(void) affinity;
 	(void) priority;
 #endif
-
-	return 0;
 }
 
 #ifdef __linux__
-
-int setAffinity(int affinity)
+void setAffinity(int affinity)
 {
 	char isolcpus[255];
 	int is_isol, ret;
@@ -109,11 +104,9 @@ int setAffinity(int affinity)
 		throw SystemError("Failed to set CPU affinity to {}", (std::string) cset_pin);
 
 	logger->debug("Set affinity to {}", (std::string) cset_pin);
-
-	return 0;
 }
 
-int setPriority(int priority)
+void setPriority(int priority)
 {
 	int ret;
 	struct sched_param param = {
@@ -127,13 +120,11 @@ int setPriority(int priority)
 		throw SystemError("Failed to set real time priority");
 
 	logger->debug("Task priority set to {}", priority);
-
-	return 0;
 }
 
-int isPreemptible()
+bool isPreemptible()
 {
-	return access(SYSFS_PATH "/kernel/realtime", R_OK);
+	return access(SYSFS_PATH "/kernel/realtime", R_OK) == 0;
 }
 
 #endif /* __linux__ */