From 82f223ea8c025b4a58f69455ccb66a3a94d46c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 25 Nov 2004 20:16:35 +0000 Subject: [PATCH] Implemented times now uses system_time, because we don't have to return a real time git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10242 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/sys/times.c | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/kernel/libroot/posix/sys/times.c b/src/kernel/libroot/posix/sys/times.c index e43d0ac758..b47251787b 100644 --- a/src/kernel/libroot/posix/sys/times.c +++ b/src/kernel/libroot/posix/sys/times.c @@ -1,24 +1,39 @@ /* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. +** Copyright 2004, Jérô Duval, jerome.duval@free.fr. +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. +** Distributed under the terms of the MIT License. */ - #include +#include +#include #include -#include clock_t times(struct tms *buffer) { - // ToDo: get some real values here! - buffer->tms_utime = 0; - buffer->tms_stime = 0; - buffer->tms_cutime = 0; - buffer->tms_cstime = 0; + team_usage_info info; + status_t err; + int32 clk_tck = 1000000 / CLK_TCK; /* to avoid overflow */ - return real_time_clock() * CLK_TCK; + if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_SELF, &info)) != B_OK) { + errno = err; + return -1; + } + + buffer->tms_utime = info.user_time / clk_tck; + buffer->tms_stime = info.kernel_time / clk_tck; + + if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_CHILDREN, &info)) != B_OK) { + errno = err; + return -1; + } + + buffer->tms_cutime = info.user_time / clk_tck; + buffer->tms_cstime = info.kernel_time / clk_tck; + + return system_time() / clk_tck; }