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
#define ERTS_SHORT_TIME_T_MAX ERTS_AINT32_T_MAX
24
#define ERTS_SHORT_TIME_T_MIN ERTS_AINT32_T_MIN
25
typedef erts_aint32_t erts_short_time_t;
27
extern erts_smp_atomic32_t do_time; /* set at clock interrupt */
28
extern SysTimeval erts_first_emu_time;
26
33
typedef struct erl_timer {
27
34
struct erl_timer* next; /* next entry tiw slot or chain */
35
struct erl_timer* prev; /* prev entry tiw slot or chain */
28
36
Uint slot; /* slot in timer wheel */
29
37
Uint count; /* number of loops remaining */
30
38
int active; /* 1=activated, 0=deactivated */
61
68
ErlTimeoutProc timeout_func,
63
70
void erts_cancel_smp_ptimer(ErtsSmpPTimer *ptimer);
75
void erts_init_time(void);
76
void erts_set_timer(ErlTimer*, ErlTimeoutProc, ErlCancelProc, void*, Uint);
77
void erts_cancel_timer(ErlTimer*);
78
void erts_bump_timer(erts_short_time_t);
79
Uint erts_timer_wheel_memory_size(void);
80
Uint erts_time_left(ErlTimer *);
81
erts_short_time_t erts_next_time(void);
84
void erts_p_slpq(void);
87
ERTS_GLB_INLINE erts_short_time_t erts_do_time_read_and_reset(void);
88
ERTS_GLB_INLINE void erts_do_time_add(erts_short_time_t);
90
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
92
ERTS_GLB_INLINE erts_short_time_t erts_do_time_read_and_reset(void)
94
erts_short_time_t time = erts_smp_atomic32_xchg_acqb(&do_time, 0);
96
erl_exit(ERTS_ABORT_EXIT, "Internal time management error\n");
100
ERTS_GLB_INLINE void erts_do_time_add(erts_short_time_t elapsed)
102
erts_smp_atomic32_add_relb(&do_time, elapsed);
105
#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */
110
#if (defined(HAVE_GETHRVTIME) || defined(HAVE_CLOCK_GETTIME))
111
# ifndef HAVE_ERTS_NOW_CPU
112
# define HAVE_ERTS_NOW_CPU
113
# ifdef HAVE_GETHRVTIME
114
# define erts_start_now_cpu() sys_start_hrvtime()
115
# define erts_stop_now_cpu() sys_stop_hrvtime()
118
void erts_get_now_cpu(Uint* megasec, Uint* sec, Uint* microsec);
121
void erts_get_timeval(SysTimeval *tv);
122
erts_time_t erts_get_time(void);
123
void erts_get_emu_time(SysTimeval *);
125
ERTS_GLB_INLINE int erts_cmp_timeval(SysTimeval *t1p, SysTimeval *t2p);
127
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
130
erts_cmp_timeval(SysTimeval *t1p, SysTimeval *t2p)
132
if (t1p->tv_sec == t2p->tv_sec) {
133
if (t1p->tv_usec < t2p->tv_usec)
135
else if (t1p->tv_usec > t2p->tv_usec)
139
return t1p->tv_sec < t2p->tv_sec ? -1 : 1;
142
#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */
143
#endif /* ERL_TIME_H__ */