From e2d1d58acf3899f4c4488b39c01f5f5ccfc5d1ba Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 2 May 2017 08:36:36 +0200 Subject: [PATCH] Alejandro changes from ESRF --- slsReceiverSoftware/include/ThreadObject.h | 2 +- slsReceiverSoftware/include/circularFifo.h | 3 ++- slsReceiverSoftware/include/logger.h | 20 +++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/include/ThreadObject.h b/slsReceiverSoftware/include/ThreadObject.h index fab511154..1f4abdf26 100644 --- a/slsReceiverSoftware/include/ThreadObject.h +++ b/slsReceiverSoftware/include/ThreadObject.h @@ -95,7 +95,7 @@ class ThreadObject : private virtual slsReceiverDefs { bool alive; /** Variable monitored by thread to kills itself */ - bool killThread; + volatile bool killThread; /** Thread variable */ pthread_t thread; diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index a5740e657..a44d6d111 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -126,7 +126,8 @@ bool CircularFifo::isEmpty() const template bool CircularFifo::isFull() const { - int tailCheck = (tail+1) % Capacity; + int tailCheck = increment(tail); + //int tailCheck = (tail+1) % Capacity; return (tailCheck == head); } diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index 2517fde5f..10de5ede3 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -125,14 +125,18 @@ inline std::string NowTime() inline std::string NowTime() { char buffer[11]; + const int buffer_len = sizeof(buffer); time_t t; time(&t); tm r = {0}; - strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); + strftime(buffer, buffer_len, "%X", localtime_r(&t, &r)); + buffer[buffer_len - 1] = 0; struct timeval tv; gettimeofday(&tv, 0); - char result[100] = {0}; - sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); + char result[100]; + const int result_len = sizeof(result); + snprintf(result, result_len, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); + result[result_len - 1] = 0; return result; } @@ -146,7 +150,8 @@ template std::ostringstream& Log::Get(TLogLevel level) lev = level; os << "- " << NowTime(); os << " " << ToString(level) << ": "; - os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t'); + if (level > logDEBUG) + os << std::string(level - logDEBUG, '\t'); return os; } @@ -218,14 +223,15 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level) FILE* pStream = Stream(); if (!pStream) return; + bool out = true; switch(level){ case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break; case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break; - case logINFO: cprintf(GRAY,"%s",msg.c_str());break; + case logINFO: cprintf(GRAY,"%s",msg.c_str()); break; // case logINFO: cprintf(DARKGRAY BOLD,"%s",msg.c_str());break; - default: fprintf(pStream,"%s",msg.c_str()); break; + default: fprintf(pStream,"%s",msg.c_str()); out = false; break; } - fflush(pStream); + fflush(out ? stdout : pStream); } #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)