xref: /haiku/src/system/libroot/posix/sys/times.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2 ** Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
3 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
4 ** Distributed under the terms of the MIT License.
5 */
6 
7 #include <OS.h>
8 
9 #include <errno.h>
10 #include <sys/resource.h>
11 #include <sys/times.h>
12 
13 #include <symbol_versioning.h>
14 
15 #include <errno_private.h>
16 #include <time_private.h>
17 #include <times_private.h>
18 
19 
20 static inline clock_t
21 times_common(struct tms* buffer, bigtime_t microSecondsPerClock)
22 {
23 	team_usage_info info;
24 	status_t err;
25 
26 	if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_SELF, &info))
27 			!= B_OK) {
28 		__set_errno(err);
29 		return -1;
30 	}
31 
32 	buffer->tms_utime = info.user_time / microSecondsPerClock;
33 	buffer->tms_stime = info.kernel_time / microSecondsPerClock;
34 
35 	if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_CHILDREN, &info))
36 			!= B_OK) {
37 		__set_errno(err);
38 		return -1;
39 	}
40 
41 	buffer->tms_cutime = info.user_time / microSecondsPerClock;
42 	buffer->tms_cstime = info.kernel_time / microSecondsPerClock;
43 
44 	return system_time() / microSecondsPerClock;
45 }
46 
47 
48 clock_t
49 __times_beos(struct tms* buffer)
50 {
51 	return times_common(buffer, MICROSECONDS_PER_CLOCK_TICK_BEOS);
52 }
53 
54 
55 clock_t
56 __times(struct tms* buffer)
57 {
58 	return times_common(buffer, MICROSECONDS_PER_CLOCK_TICK);
59 }
60 
61 
62 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__times_beos", "times@", "BASE");
63 
64 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__times", "times@@", "1_ALPHA4");
65