7 #include "stg/common.h"
11 void * StgTimer(void *);
14 static pthread_t thrStgTimer;
15 static bool isTimerRunning = false;
16 volatile time_t stgTime;
18 const int TIME_SPEED = 1;
26 const int START_TIME = 0;
29 1 - start before new day (3 min before) 29.11.2005 23:57:00
30 2 - start before new month (3 min before) 30.11.2005 23:57:00
33 //-----------------------------------------------------------------------------
34 void * StgTimer(void *)
36 #ifdef STG_TIMER_DEBUG
38 memset(<, 0, sizeof(lt));
40 lt.tm_year = 2007 - 1900; // 2005
41 lt.tm_mon = 11 - 1; // Nov
42 lt.tm_hour = 23; // 23 h
43 lt.tm_min = 57; // 50 min
44 lt.tm_sec = 0; // 00 sec
54 stgTime = mktime(<);
59 stgTime = mktime(<);
67 sigfillset(&signalSet);
68 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
71 isTimerRunning = true;
74 #ifdef STG_TIMER_DEBUG
75 struct timespec ts = {0, 1000000000 / TIME_SPEED};
79 struct timespec ts = {0, 500000000};
84 isTimerRunning = false;
88 //-----------------------------------------------------------------------------
92 isTimerRunning = false;
95 if (pthread_create(&thrStgTimer, NULL, &StgTimer, NULL))
97 isTimerRunning = false;
104 //-----------------------------------------------------------------------------
108 pthread_join(thrStgTimer, NULL); // Cleanup thread resources
109 printfd(__FILE__, "STG_TIMER stopped\n");
111 //-----------------------------------------------------------------------------
112 bool IsStgTimerRunning()
114 return isTimerRunning;
116 //-----------------------------------------------------------------------------
117 int stgUsleep(unsigned long t)
119 #ifdef STG_TIMER_DEBUG
120 struct timespec ts = {static_cast<time_t>((t / TIME_SPEED) / 1000000), static_cast<long>(((t / TIME_SPEED) % 1000000) * 1000)};
121 return nanosleep(&ts, NULL);
123 struct timespec ts = {static_cast<time_t>(t / 1000000), static_cast<long>((t % 1000000) * 1000)};
124 return nanosleep(&ts, NULL);
127 //-----------------------------------------------------------------------------
130 for (int i = 0; i < 5 && !isTimerRunning; i++)
133 //-----------------------------------------------------------------------------