7 #include "stg/common.h"
10 static pthread_t thrStgTimer;
11 static bool isTimerRunning = false;
12 volatile time_t stgTime;
14 const int TIME_SPEED = 1;
22 const int START_TIME = 0;
25 1 - start before new day (3 min before) 29.11.2005 23:57:00
26 2 - start before new month (3 min before) 30.11.2005 23:57:00
29 //-----------------------------------------------------------------------------
30 void * StgTimer(void *)
32 #ifdef STG_TIMER_DEBUG
34 memset(<, 0, sizeof(lt));
36 lt.tm_year = 2007 - 1900; // 2005
37 lt.tm_mon = 11 - 1; // Nov
38 lt.tm_hour = 23; // 23 h
39 lt.tm_min = 57; // 50 min
40 lt.tm_sec = 0; // 00 sec
50 stgTime = mktime(<);
55 stgTime = mktime(<);
63 sigfillset(&signalSet);
64 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
67 isTimerRunning = true;
70 #ifdef STG_TIMER_DEBUG
71 struct timespec ts = {0, 1000000000 / TIME_SPEED};
75 struct timespec ts = {0, 500000000};
80 isTimerRunning = false;
84 //-----------------------------------------------------------------------------
88 isTimerRunning = false;
91 if (pthread_create(&thrStgTimer, NULL, StgTimer, NULL))
93 isTimerRunning = false;
100 //-----------------------------------------------------------------------------
104 pthread_join(thrStgTimer, NULL); // Cleanup thread resources
105 printfd(__FILE__, "STG_TIMER stopped\n");
107 //-----------------------------------------------------------------------------
108 bool IsStgTimerRunning()
110 return isTimerRunning;
112 //-----------------------------------------------------------------------------
113 int stgUsleep(unsigned long t)
115 #ifdef STG_TIMER_DEBUG
116 struct timespec ts = {(t / TIME_SPEED) / 1000000, ((t / TIME_SPEED) % 1000000) * 1000};
117 return nanosleep(&ts, NULL);
119 struct timespec ts = {t / 1000000, (t % 1000000) * 1000};
120 return nanosleep(&ts, NULL);
123 //-----------------------------------------------------------------------------
126 for (int i = 0; i < 5 && !isTimerRunning; i++)
129 //-----------------------------------------------------------------------------