Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SU_TIME_H
00026
00027 #define SU_TIME_H
00028
00037 #ifndef SU_TYPES_H
00038 #include "sofia-sip/su_types.h"
00039 #endif
00040
00041 SOFIA_BEGIN_DECLS
00042
00048 struct su_time_s {
00049 unsigned long tv_sec;
00050 unsigned long tv_usec;
00051 };
00053 typedef struct su_time_s su_time_t;
00054
00061 typedef long su_duration_t;
00062
00063 enum {
00065 SU_DURATION_MAX = 0x7fffffffL
00066 };
00067 #define SU_DURATION_MAX SU_DURATION_MAX
00068
00074 typedef uint64_t su_ntp_t;
00075
00077 #define SU_NTP_C(x) SU_U64_C(x)
00078
00079 #define SU_TIME_CMP(t1, t2) su_time_cmp(t1, t2)
00080
00082 #define SU_TIME_EPOCH 2208988800UL
00083
00084 typedef uint64_t su_nanotime_t;
00085
00086 #define SU_E9 (1000000000U)
00087
00088 SOFIAPUBFUN su_nanotime_t su_nanotime(su_nanotime_t *return_time);
00089 SOFIAPUBFUN su_nanotime_t su_monotime(su_nanotime_t *return_time);
00090
00091 SOFIAPUBFUN su_time_t su_now(void);
00092 SOFIAPUBFUN void su_time(su_time_t *tv);
00093 SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
00094 SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
00095 SOFIAPUBFUN su_duration_t su_duration(su_time_t const t1, su_time_t const t2);
00096
00097 SOFIAPUBFUN su_time_t su_time_add(su_time_t t, su_duration_t dur);
00098 SOFIAPUBFUN su_time_t su_time_dadd(su_time_t t, double dur);
00099
00100 SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv);
00101
00102 #define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec)))
00103
00104 SOFIAPUBFUN su_ntp_t su_ntp_now(void);
00105 SOFIAPUBFUN uint32_t su_ntp_sec(void);
00106 SOFIAPUBFUN uint32_t su_ntp_hi(su_ntp_t);
00107 SOFIAPUBFUN uint32_t su_ntp_lo(su_ntp_t);
00108 SOFIAPUBFUN uint32_t su_ntp_mw(su_ntp_t ntp);
00109
00110 #if !SU_HAVE_INLINE
00111 SOFIAPUBFUN uint32_t su_ntp_fraq(su_time_t t);
00112 SOFIAPUBFUN uint32_t su_time_ms(su_time_t t);
00113 #else
00114 su_inline uint32_t su_ntp_fraq(su_time_t t);
00115 su_inline uint32_t su_time_ms(su_time_t t);
00116 #endif
00117
00118 SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
00119
00120 SOFIAPUBFUN uint64_t su_counter(void);
00121
00122 SOFIAPUBFUN uint64_t su_nanocounter(void);
00123
00124 SOFIAPUBFUN uint32_t su_random(void);
00125
00126 #if SU_HAVE_INLINE
00127
00128 su_inline uint32_t su_ntp_fraq(su_time_t t)
00129 {
00130
00131
00132
00133
00134
00135 return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625;
00136 }
00137
00139 su_inline uint32_t su_time_ms(su_time_t t)
00140 {
00141 return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
00142 }
00143 #endif
00144
00145 SOFIA_END_DECLS
00146
00147 #endif