From 0c711c79c9ee9603614198e6e8a295712abc63aa Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 22 Jan 2019 16:00:46 +0100 Subject: [PATCH] utils: move killme() to C++ code in order to avoid global objects --- common/include/villas/utils.h | 2 -- common/lib/utils.c | 11 ----------- common/lib/utils.cpp | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/common/include/villas/utils.h b/common/include/villas/utils.h index fef301fe9..e81598b5f 100644 --- a/common/include/villas/utils.h +++ b/common/include/villas/utils.h @@ -37,8 +37,6 @@ extern "C" { #include #include -extern pthread_t main_thread; - #ifdef __GNUC__ #define LIKELY(x) __builtin_expect((x),1) #define UNLIKELY(x) __builtin_expect((x),0) diff --git a/common/lib/utils.c b/common/lib/utils.c index e735e51b6..6b911002e 100644 --- a/common/lib/utils.c +++ b/common/lib/utils.c @@ -34,8 +34,6 @@ #include #include -pthread_t main_thread; - double box_muller(float m, float s) { double x1, x2, y1; @@ -113,15 +111,6 @@ void * memdup(const void *src, size_t bytes) return dst; } -void killme(int sig) -{ - /* Send only to main thread in case the ID was initilized by signals_init() */ - if (main_thread) - pthread_kill(main_thread, sig); - else - kill(0, sig); -} - pid_t spawn(const char* name, char *const argv[]) { pid_t pid; diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp index ea2f4d259..864f40748 100644 --- a/common/lib/utils.cpp +++ b/common/lib/utils.cpp @@ -35,6 +35,8 @@ namespace villas { namespace utils { +static pthread_t main_thread; + std::vector tokenize(std::string s, std::string delimiter) { @@ -156,5 +158,18 @@ char * decolor(char *str) return str; } +extern "C" { + +void killme(int sig) +{ + /* Send only to main thread in case the ID was initilized by signals_init() */ + if (main_thread) + pthread_kill(main_thread, sig); + else + kill(0, sig); +} + +} + } // namespace utils } // namespace villas