btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / system / libroot / os / time.cpp
blob5bf32fae7b28835e1c3d1ec53000e3b1e92ab9e3
1 /*
2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <errno.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <syslog.h>
12 #include <FindDirectory.h>
13 #include <OS.h>
15 #include <commpage_defs.h>
16 #include <errno_private.h>
17 #include <libroot_private.h>
18 #include <real_time_data.h>
19 #include <user_timer_defs.h>
20 #include <syscalls.h>
23 static struct real_time_data* sRealTimeData;
26 void
27 __init_time(addr_t commPageTable)
29 sRealTimeData = (struct real_time_data*)
30 (((addr_t*)commPageTable)[COMMPAGE_ENTRY_REAL_TIME_DATA]
31 + commPageTable);
33 __arch_init_time(sRealTimeData, false);
37 bigtime_t
38 __get_system_time_offset()
40 return __arch_get_system_time_offset(sRealTimeData);
44 // #pragma mark - public API
47 unsigned long
48 real_time_clock(void)
50 return (__arch_get_system_time_offset(sRealTimeData) + system_time())
51 / 1000000;
55 bigtime_t
56 real_time_clock_usecs(void)
58 return __arch_get_system_time_offset(sRealTimeData) + system_time();
62 void
63 set_real_time_clock(unsigned long secs)
65 _kern_set_real_time_clock((bigtime_t)secs * 1000000);
69 status_t
70 set_timezone(const char* /*timezone*/)
72 /* There's nothing we can do here, since we no longer support named
73 * timezones.
75 * TODO: should we keep this around for compatibility or get rid of it?
77 return ENOSYS;
81 bigtime_t
82 set_alarm(bigtime_t when, uint32 mode)
84 // prepare the values to be passed to the kernel
85 bigtime_t interval = 0;
86 uint32 flags = B_RELATIVE_TIMEOUT;
88 if (when == B_INFINITE_TIMEOUT) {
89 when = B_INFINITE_TIMEOUT;
90 } else {
91 switch (mode) {
92 case B_PERIODIC_ALARM:
93 interval = when;
94 break;
95 case B_ONE_SHOT_ABSOLUTE_ALARM:
96 flags = B_ABSOLUTE_TIMEOUT;
97 break;
98 case B_ONE_SHOT_RELATIVE_ALARM:
99 default:
100 break;
104 // set the timer
105 user_timer_info oldInfo;
106 status_t error = _kern_set_timer(USER_TIMER_REAL_TIME_ID, find_thread(NULL),
107 when, interval, flags, &oldInfo);
108 if (error != B_OK)
109 return 0;
111 // A remaining time of B_INFINITE_TIMEOUT means not scheduled.
112 return oldInfo.remaining_time != B_INFINITE_TIMEOUT
113 ? oldInfo.remaining_time : 0;