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 = 0;
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 = 2007 - 1900; // 2005
43 lt.tm_mon = 11 - 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
77 struct timespec ts = {0, 1000000000 / TIME_SPEED};
81 struct timespec ts = {0, 500000000};
86 isTimerRunning = false;
90 //-----------------------------------------------------------------------------
94 isTimerRunning = false;
97 if (pthread_create(&thrStgTimer, NULL, &StgTimer, NULL))
99 isTimerRunning = false;
106 //-----------------------------------------------------------------------------
110 pthread_join(thrStgTimer, NULL); // Cleanup thread resources
111 printfd(__FILE__, "STG_TIMER stopped\n");
113 //-----------------------------------------------------------------------------
114 bool IsStgTimerRunning()
116 return isTimerRunning;
118 //-----------------------------------------------------------------------------
119 int stgUsleep(unsigned long t)
121 #ifdef STG_TIMER_DEBUG
122 struct timespec ts = {static_cast<time_t>((t / TIME_SPEED) / 1000000), static_cast<long>(((t / TIME_SPEED) % 1000000) * 1000)};
123 return nanosleep(&ts, NULL);
125 struct timespec ts = {static_cast<time_t>(t / 1000000), static_cast<long>((t % 1000000) * 1000)};
126 return nanosleep(&ts, NULL);
129 //-----------------------------------------------------------------------------
132 for (int i = 0; i < 5 && !isTimerRunning; i++)
135 //-----------------------------------------------------------------------------