Cygwin: lockf: Fix adding a new lock over multiple locks
[newlib-cygwin.git] / libgloss / riscv / sys_times.c
bloba029bcfb56360de6afa0ded1d322bf326afeb650
1 #include <machine/syscall.h>
2 #include <sys/types.h>
3 #include <sys/times.h>
4 #include <sys/time.h>
5 #include "internal_syscall.h"
7 extern int _gettimeofday(struct timeval *, void *);
9 /* Timing information for current process. From
10 newlib/libc/include/sys/times.h the tms struct fields are as follows:
12 - clock_t tms_utime : user clock ticks
13 - clock_t tms_stime : system clock ticks
14 - clock_t tms_cutime : children's user clock ticks
15 - clock_t tms_cstime : children's system clock ticks
17 Since maven does not currently support processes we set both of the
18 children's times to zero. Eventually we might want to separately
19 account for user vs system time, but for now we just return the total
20 number of cycles since starting the program. */
21 clock_t
22 _times(struct tms *buf)
24 static char initialized;
25 static struct timeval t0;
26 struct timeval t;
28 _gettimeofday (&t, 0);
30 // when called for the first time, initialize t0
31 if (!initialized) {
32 t0.tv_sec = t.tv_sec;
33 t0.tv_usec = t.tv_usec;
34 initialized = 1;
37 long long utime = (t.tv_sec - t0.tv_sec) * 1000000 + (t.tv_usec - t0.tv_usec);
38 buf->tms_utime = utime * CLOCKS_PER_SEC / 1000000;
39 buf->tms_stime = buf->tms_cstime = buf->tms_cutime = 0;
41 return buf->tms_utime;