Make UEFI boot-platform build again
[haiku.git] / headers / private / libroot / time_private.h
blob0cfd9faa6dd2e32e96db5027ed6a1407e5fa4acf
1 /*
2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _LIBROOT_TIME_PRIVATE_H
6 #define _LIBROOT_TIME_PRIVATE_H
9 #include <errno.h>
10 #include <sys/cdefs.h>
11 #include <sys/time.h>
12 #include <time.h>
14 #include <SupportDefs.h>
16 #include <new>
18 #define CLOCKS_PER_SEC_BEOS 1000
19 #define CLK_TCK_BEOS CLOCKS_PER_SEC_BEOS
21 #define MICROSECONDS_PER_CLOCK_TICK (1000000 / CLOCKS_PER_SEC)
22 #define MICROSECONDS_PER_CLOCK_TICK_BEOS (1000000 / CLOCKS_PER_SEC_BEOS)
25 struct __timer_t {
26 int32 id;
27 thread_id thread;
29 void SetTo(int32 id, thread_id thread)
31 this->id = id;
32 this->thread = thread;
37 static inline void
38 bigtime_to_timespec(bigtime_t time, timespec& spec)
40 spec.tv_sec = time / 1000000;
41 spec.tv_nsec = (time % 1000000) * 1000;
45 static inline bool
46 timespec_to_bigtime(const timespec& spec, bigtime_t& _time)
48 if (spec.tv_sec < 0 || spec.tv_nsec < 0 || spec.tv_nsec >= 1000000000)
49 return false;
51 _time = (bigtime_t)spec.tv_sec * 1000000 + (spec.tv_nsec + 999) / 1000;
53 return true;
57 static inline bool
58 timeval_to_timespec(const timeval& val, timespec& spec)
60 if (val.tv_sec < 0 || val.tv_usec < 0 || val.tv_usec >= 1000000)
61 return false;
63 spec.tv_sec = val.tv_sec;
64 spec.tv_nsec = val.tv_usec * 1000;
66 return true;
70 static inline void
71 timespec_to_timeval(const timespec& spec, timeval& val)
73 val.tv_sec = spec.tv_sec;
74 val.tv_usec = spec.tv_nsec / 1000;
78 __BEGIN_DECLS
81 clock_t __clock_beos(void);
82 clock_t __clock(void);
85 __END_DECLS
88 #endif // _LIBROOT_TIME_PRIVATE_H