Added more unittest coverage

Added Mutex for gmtime functions
Moved Statics used in ClockCommon to ClockCommon
This commit is contained in:
2022-03-25 18:47:31 +01:00
parent d0fec93dc3
commit 10398855a9
11 changed files with 266 additions and 13 deletions

View File

@ -9,9 +9,7 @@
#include <fstream>
#include "fsfw/serviceinterface/ServiceInterface.h"
uint16_t Clock::leapSeconds = 0;
MutexIF* Clock::timeMutex = NULL;
#include "fsfw/ipc/MutexGuard.h"
uint32_t Clock::getTicksPerSecond(void) {
uint32_t ticks = sysconf(_SC_CLK_TCK);
@ -117,7 +115,13 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
// TODO errno
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t result = checkOrCreateClockMutex();
if(result != HasReturnvaluesIF::RETURN_OK){
return result;
}
MutexGuard helper(timeMutex);
// gmtime writes its output in a global buffer which is not Thread Safe
// Therefore we have to use a Mutex here
struct tm* timeInfo;
timeInfo = gmtime(&timeUnix.tv_sec);
time->year = timeInfo->tm_year + 1900;