Author: bonefish Date: 2011-06-05 01:33:05 +0200 (Sun, 05 Jun 2011) New Revision: 41918 Changeset: https://dev.haiku-os.org/changeset/41918 Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/itimer.cpp Log: Added support for ITIMER_VIRTUAL and ITIMER_PROF, at least in terms of mapping them to the respective timer IDs. ITIMER_VIRTUAL can't work, since the underlying timer USER_TIMER_TEAM_USER_TIME_ID isn't implemented in the kernel yet. Not sure, if it is worth the hassle -- the *itimer() interface is marked obsolescent in the current POSIX specs. ITIMER_PROF should work, but still has issues. Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/itimer.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/itimer.cpp 2011-06-04 23:28:12 UTC (rev 41917) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/itimer.cpp 2011-06-04 23:33:05 UTC (rev 41918) @@ -36,19 +36,37 @@ } +static bool +prepare_timer(__timer_t& timer, int which) +{ + switch (which) { + case ITIMER_REAL: + timer.SetTo(USER_TIMER_REAL_TIME_ID, -1); + return true; + case ITIMER_VIRTUAL: + timer.SetTo(USER_TIMER_TEAM_USER_TIME_ID, -1); + return true; + case ITIMER_PROF: + timer.SetTo(USER_TIMER_TEAM_TOTAL_TIME_ID, -1); + return true; + } + + return false; +} + + // #pragma mark - int getitimer(int which, struct itimerval* value) { - if (which != ITIMER_REAL) - RETURN_AND_SET_ERRNO(B_NOT_SUPPORTED); - - // prepare the respective timer and let timer_gettime() do the job + // prepare the respective timer __timer_t timer; - timer.SetTo(USER_TIMER_REAL_TIME_ID, -1); + if (!prepare_timer(timer, which)) + RETURN_AND_SET_ERRNO(EINVAL); + // let timer_gettime() do the job itimerspec valueSpec; if (timer_gettime(&timer, &valueSpec) != 0) return -1; @@ -63,22 +81,17 @@ int setitimer(int which, const struct itimerval* value, struct itimerval* oldValue) { - // TODO: implement me properly! - // We probably need a better internal set_alarm() implementation to do this + // prepare the respective timer + __timer_t timer; + if (!prepare_timer(timer, which)) + RETURN_AND_SET_ERRNO(EINVAL); - // Only real time timers work at all. - if (which != ITIMER_REAL) - RETURN_AND_SET_ERRNO(B_NOT_SUPPORTED); - // convert value to itimerspec itimerspec valueSpec; if (!itimerval_to_itimerspec(*value, valueSpec)) RETURN_AND_SET_ERRNO(EINVAL); - // prepare the respective timer and let timer_settime() do the job - __timer_t timer; - timer.SetTo(USER_TIMER_REAL_TIME_ID, -1); - + // let timer_settime() do the job itimerspec oldValueSpec; if (timer_settime(&timer, 0, &valueSpec, oldValue != NULL ? &oldValueSpec : NULL) != 0) {