Fix for rare mono runtime crash during shutdown sequence on Windows.
[mono.git] / mono / utils / mono-time.h
1 #ifndef __UTILS_MONO_TIME_H__
2 #define __UTILS_MONO_TIME_H__
3
4 #include <mono/utils/mono-compiler.h>
5 #include <glib.h>
6
7 #ifdef HAVE_SYS_TIME_H
8 #include <sys/time.h>
9 #endif
10
11 /* Returns the number of milliseconds from boot time: this should be monotonic */
12 guint32 mono_msec_ticks      (void);
13
14 /* Returns the number of 100ns ticks from unspecified time: this should be monotonic */
15 gint64  mono_100ns_ticks     (void);
16
17 /* Returns the number of 100ns ticks since 1/1/1601, UTC timezone */
18 gint64  mono_100ns_datetime  (void);
19
20 #ifndef HOST_WIN32
21 gint64 mono_100ns_datetime_from_timeval (struct timeval tv);
22 #endif
23
24 /* Stopwatch class for internal runtime use */
25 typedef struct {
26         gint64 start, stop;
27 } MonoStopwatch;
28
29 static inline void
30 mono_stopwatch_start (MonoStopwatch *w)
31 {
32         w->start = mono_100ns_ticks ();
33         w->stop = 0;
34 }
35
36 static inline void
37 mono_stopwatch_stop (MonoStopwatch *w)
38 {
39         w->stop = mono_100ns_ticks ();
40 }
41
42 static inline guint64
43 mono_stopwatch_elapsed (MonoStopwatch *w)
44 {
45         return (w->stop - w->start) / 10;
46 }
47
48 static inline guint64
49 mono_stopwatch_elapsed_ms (MonoStopwatch *w)
50 {
51         return (mono_stopwatch_elapsed (w) + 500) / 1000;
52 }
53
54 #endif /* __UTILS_MONO_TIME_H__ */
55