3 #include "stg/common.h"
11 void * StgTimer(void *);
14 static pthread_t thrStgTimer;
15 static bool isTimerRunning = false;
16 volatile time_t stgTime;
18 #ifdef STG_TIMER_DEBUG
19 const int TIME_SPEED = 1;
27 const int START_TIME = 2;
30 1 - start before new day (3 min before) 29.11.2005 23:57:00
31 2 - start before new month (3 min before) 30.11.2005 23:57:00
35 //-----------------------------------------------------------------------------
36 void * StgTimer(void *)
38 #ifdef STG_TIMER_DEBUG
40 memset(<, 0, sizeof(lt));
42 lt.tm_year = 2016 - 1900; // 2005
43 lt.tm_mon = 7 - 1; // Nov
44 lt.tm_hour = 23; // 23 h
45 lt.tm_min = 57; // 50 min
46 lt.tm_sec = 0; // 00 sec
57 stgTime = mktime(<);
62 stgTime = mktime(<);
70 sigfillset(&signalSet);
71 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
74 isTimerRunning = true;
77 #ifdef STG_TIMER_DEBUG
87 ts.tv_nsec = 1000000000 / TIME_SPEED;
92 struct timespec ts = {0, 500000000};
97 isTimerRunning = false;
101 //-----------------------------------------------------------------------------
105 isTimerRunning = false;
108 if (pthread_create(&thrStgTimer, NULL, &StgTimer, NULL))
110 isTimerRunning = false;
117 //-----------------------------------------------------------------------------
121 pthread_join(thrStgTimer, NULL); // Cleanup thread resources
122 printfd(__FILE__, "STG_TIMER stopped\n");
124 //-----------------------------------------------------------------------------
125 bool IsStgTimerRunning()
127 return isTimerRunning;
129 //-----------------------------------------------------------------------------
130 int stgUsleep(unsigned long t)
132 #ifdef STG_TIMER_DEBUG
133 struct timespec ts = {static_cast<time_t>((t / TIME_SPEED) / 1000000), static_cast<long>(((t / TIME_SPEED) % 1000000) * 1000)};
134 return nanosleep(&ts, NULL);
136 struct timespec ts = {static_cast<time_t>(t / 1000000), static_cast<long>((t % 1000000) * 1000)};
137 return nanosleep(&ts, NULL);
140 //-----------------------------------------------------------------------------
143 for (int i = 0; i < 5 && !isTimerRunning; i++)
146 //-----------------------------------------------------------------------------