3 #include "stg/common.h"
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wshadow"
8 #pragma GCC diagnostic pop
23 void * StgTimer(void *);
25 static bool isTimerRunning = false;
26 volatile time_t stgTime;
28 #ifdef STG_TIMER_DEBUG
29 const int TIME_SPEED = 1;
37 const int START_TIME = 2;
40 1 - start before new day (3 min before) 29.11.2005 23:57:00
41 2 - start before new month (3 min before) 30.11.2005 23:57:00
45 //-----------------------------------------------------------------------------
46 void timer(std::stop_token token)
48 #ifdef STG_TIMER_DEBUG
50 memset(<, 0, sizeof(lt));
52 lt.tm_year = 2016 - 1900; // 2005
53 lt.tm_mon = 7 - 1; // Nov
54 lt.tm_hour = 23; // 23 h
55 lt.tm_min = 57; // 50 min
56 lt.tm_sec = 0; // 00 sec
67 stgTime = mktime(<);
72 stgTime = mktime(<);
80 sigfillset(&signalSet);
81 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
83 isTimerRunning = true;
84 while (!token.stop_requested())
86 #ifdef STG_TIMER_DEBUG
96 ts.tv_nsec = 1000000000 / TIME_SPEED;
101 struct timespec ts = {0, 500000000};
102 nanosleep(&ts, NULL);
103 stgTime = time(NULL);
106 isTimerRunning = false;
108 //-----------------------------------------------------------------------------
111 isTimerRunning = false;
113 if (!thread.joinable())
114 thread = std::jthread(timer);
118 //-----------------------------------------------------------------------------
121 thread.request_stop();
123 printfd(__FILE__, "STG_TIMER stopped\n");
125 //-----------------------------------------------------------------------------
126 bool IsStgTimerRunning()
128 return isTimerRunning;
130 //-----------------------------------------------------------------------------
131 int stgUsleep(unsigned long t)
133 #ifdef STG_TIMER_DEBUG
134 struct timespec ts = {static_cast<time_t>((t / TIME_SPEED) / 1000000), static_cast<long>(((t / TIME_SPEED) % 1000000) * 1000)};
135 return nanosleep(&ts, NULL);
137 struct timespec ts = {static_cast<time_t>(t / 1000000), static_cast<long>((t % 1000000) * 1000)};
138 return nanosleep(&ts, NULL);
141 //-----------------------------------------------------------------------------
144 for (int i = 0; i < 5 && !isTimerRunning; i++)
147 //-----------------------------------------------------------------------------