1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_htimmstime.c - standard hierarchical timer for microsecond
7 (C) Copyright 2003 by Pavel Pisa - Originator
9 The uLan utilities library can be used, copied and modified under
11 - GPL - GNU General Public License
12 - LGPL - GNU Lesser General Public License
13 - MPL - Mozilla Public License
14 - and other licenses added by project originators
15 Code can be modified and re-distributed under any combination
16 of the above listed licenses. If contributor does not agree with
17 some of the licenses, he/she can delete appropriate line.
18 Warning, if you delete all lines, you are not allowed to
19 distribute source code and/or binaries utilizing code.
21 See files COPYING and README for details.
23 *******************************************************************/
27 #include "ul_gavlflesint.h"
28 #include "ul_htimer.h"
30 #ifdef UL_HTIMER_WITH_MSTIME
35 ul_htimer_queue_t ul_root_htimer;
37 ul_mstime_t ul_mstime_last;
38 ul_mstime_t ul_mstime_next;
40 static ul_mstime_t ul_mstime_base_offs;
46 void ul_mstime_now(ul_mstime_t *mstm)
48 struct timeval tv_actual;
49 ul_mstime_t ms_actual;
51 gettimeofday(&tv_actual,NULL);
53 ms_actual=sec*1000+tv_actual.tv_usec/1000+ul_mstime_base_offs;
58 #include <sys/timeb.h>
60 void ul_mstime_now(ul_mstime_t *mstm)
62 struct timeb tb_actual;
63 ul_mstime_t ms_actual;
67 ms_actual=sec*1000+tb_actual.millitm+ul_mstime_base_offs;
72 void ul_mstime_update(void)
74 ul_mstime_now(&ul_mstime_last);
77 void ul_mstime_init(void)
80 ul_mstime_base_offs=-ul_mstime_last;
85 ul_get_log_time_str(char str[30])
91 log_tm=localtime(&log_time);
92 sprintf(str,"%04d-%02d-%02d %02d:%02d:%02d",
93 (int)log_tm->tm_year+1900,(int)log_tm->tm_mon+1,
94 (int)log_tm->tm_mday,(int)log_tm->tm_hour,
95 (int)log_tm->tm_min,(int)log_tm->tm_sec);
98 void ul_compute_mstime_next(void)
100 if(!ul_htimer_next_expire(&ul_root_htimer,&ul_mstime_next))
101 ul_mstime_next=ul_mstime_last+0x10000000;
105 #endif /*UL_HTIMER_WITH_MSTIME*/