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
56 stgTime = mktime(<);
61 stgTime = mktime(<);
69 sigfillset(&signalSet);
70 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
73 isTimerRunning = true;
76 #ifdef STG_TIMER_DEBUG
86 ts.tv_nsec = 1000000000 / TIME_SPEED;
91 struct timespec ts = {0, 500000000};
96 isTimerRunning = false;
100 //-----------------------------------------------------------------------------
104 isTimerRunning = false;
107 if (pthread_create(&thrStgTimer, NULL, &StgTimer, NULL))
109 isTimerRunning = false;
116 //-----------------------------------------------------------------------------
120 pthread_join(thrStgTimer, NULL); // Cleanup thread resources
121 printfd(__FILE__, "STG_TIMER stopped\n");
123 //-----------------------------------------------------------------------------
124 bool IsStgTimerRunning()
126 return isTimerRunning;
128 //-----------------------------------------------------------------------------
129 int stgUsleep(unsigned long t)
131 #ifdef STG_TIMER_DEBUG
132 struct timespec ts = {static_cast<time_t>((t / TIME_SPEED) / 1000000), static_cast<long>(((t / TIME_SPEED) % 1000000) * 1000)};
133 return nanosleep(&ts, NULL);
135 struct timespec ts = {static_cast<time_t>(t / 1000000), static_cast<long>((t % 1000000) * 1000)};
136 return nanosleep(&ts, NULL);
139 //-----------------------------------------------------------------------------
142 for (int i = 0; i < 5 && !isTimerRunning; i++)
145 //-----------------------------------------------------------------------------