2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de.
5 * Distributed under the terms of the MIT License.
16 #include <errno_private.h>
17 #include <syscall_utils.h>
19 #include <user_timer_defs.h>
21 #include <time_private.h>
25 itimerval_to_itimerspec(const itimerval
& val
, itimerspec
& spec
)
27 return timeval_to_timespec(val
.it_value
, spec
.it_value
)
28 && timeval_to_timespec(val
.it_interval
, spec
.it_interval
);
33 itimerspec_to_itimerval(const itimerspec
& spec
, itimerval
& val
)
35 timespec_to_timeval(spec
.it_value
, val
.it_value
);
36 timespec_to_timeval(spec
.it_interval
, val
.it_interval
);
41 prepare_timer(__timer_t
& timer
, int which
)
45 timer
.SetTo(USER_TIMER_REAL_TIME_ID
, -1);
48 timer
.SetTo(USER_TIMER_TEAM_USER_TIME_ID
, -1);
51 timer
.SetTo(USER_TIMER_TEAM_TOTAL_TIME_ID
, -1);
63 getitimer(int which
, struct itimerval
* value
)
65 // prepare the respective timer
67 if (!prepare_timer(timer
, which
))
68 RETURN_AND_SET_ERRNO(EINVAL
);
70 // let timer_gettime() do the job
72 if (timer_gettime(&timer
, &valueSpec
) != 0)
75 // convert back to itimerval value
76 itimerspec_to_itimerval(valueSpec
, *value
);
83 setitimer(int which
, const struct itimerval
* value
, struct itimerval
* oldValue
)
85 // prepare the respective timer
87 if (!prepare_timer(timer
, which
))
88 RETURN_AND_SET_ERRNO(EINVAL
);
90 // convert value to itimerspec
92 if (!itimerval_to_itimerspec(*value
, valueSpec
))
93 RETURN_AND_SET_ERRNO(EINVAL
);
95 // let timer_settime() do the job
96 itimerspec oldValueSpec
;
97 if (timer_settime(&timer
, 0, &valueSpec
,
98 oldValue
!= NULL
? &oldValueSpec
: NULL
) != 0) {
102 // convert back to itimerval oldValue
103 if (oldValue
!= NULL
)
104 itimerspec_to_itimerval(oldValueSpec
, *oldValue
);