4
* Copyright Ericsson AB 2006-2009. All Rights Reserved.
4
* Copyright Ericsson AB 2006-2011. All Rights Reserved.
6
6
* The contents of this file are subject to the Erlang Public License,
7
7
* Version 1.1, (the "License"); you may not use this file except in
20
20
#ifndef ERL_TIME_H__
21
21
#define ERL_TIME_H__
23
extern erts_smp_atomic_t do_time; /* set at clock interrupt */
24
extern SysTimeval erts_first_emu_time;
26
29
typedef struct erl_timer {
27
30
struct erl_timer* next; /* next entry tiw slot or chain */
31
struct erl_timer* prev; /* prev entry tiw slot or chain */
28
32
Uint slot; /* slot in timer wheel */
29
33
Uint count; /* number of loops remaining */
30
34
int active; /* 1=activated, 0=deactivated */
61
64
ErlTimeoutProc timeout_func,
63
66
void erts_cancel_smp_ptimer(ErtsSmpPTimer *ptimer);
71
void erts_init_time(void);
72
void erts_set_timer(ErlTimer*, ErlTimeoutProc, ErlCancelProc, void*, Uint);
73
void erts_cancel_timer(ErlTimer*);
74
void erts_bump_timer(erts_aint_t);
75
Uint erts_timer_wheel_memory_size(void);
76
Uint erts_time_left(ErlTimer *);
77
erts_aint_t erts_next_time(void);
80
void erts_p_slpq(void);
83
ERTS_GLB_INLINE erts_aint_t erts_do_time_read_and_reset(void);
84
ERTS_GLB_INLINE void erts_do_time_add(long);
86
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
88
ERTS_GLB_INLINE erts_aint_t erts_do_time_read_and_reset(void) { return erts_smp_atomic_xchg(&do_time, 0L); }
89
ERTS_GLB_INLINE void erts_do_time_add(long elapsed) { erts_smp_atomic_add(&do_time, elapsed); }
91
#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */
96
#if (defined(HAVE_GETHRVTIME) || defined(HAVE_CLOCK_GETTIME))
97
# ifndef HAVE_ERTS_NOW_CPU
98
# define HAVE_ERTS_NOW_CPU
99
# ifdef HAVE_GETHRVTIME
100
# define erts_start_now_cpu() sys_start_hrvtime()
101
# define erts_stop_now_cpu() sys_stop_hrvtime()
104
void erts_get_now_cpu(Uint* megasec, Uint* sec, Uint* microsec);
107
void erts_get_timeval(SysTimeval *tv);
108
long erts_get_time(void);
109
void erts_get_emu_time(SysTimeval *);
111
ERTS_GLB_INLINE int erts_cmp_timeval(SysTimeval *t1p, SysTimeval *t2p);
113
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
116
erts_cmp_timeval(SysTimeval *t1p, SysTimeval *t2p)
118
if (t1p->tv_sec == t2p->tv_sec) {
119
if (t1p->tv_usec < t2p->tv_usec)
121
else if (t1p->tv_usec > t2p->tv_usec)
125
return t1p->tv_sec < t2p->tv_sec ? -1 : 1;
128
#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */
129
#endif /* ERL_TIME_H__ */