Author: bonefish Date: 2011-05-30 23:31:40 +0200 (Mon, 30 May 2011) New Revision: 41838 Changeset: https://dev.haiku-os.org/changeset/41838 Added: haiku/branches/developer/bonefish/signals/headers/private/libroot/time_private.h Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/timer_support.cpp Log: * Created libroot private header timer_private.h and moved struct __timer_t and helper functions bigtime_to_timespec() and timespec_to_bigtime() there. * Added SetTo() method to __timer_t for convenience. * info_to_itimerspec(): Missing braces. Fixes spec.it_value.tv_nsec always being set to 0. Added: haiku/branches/developer/bonefish/signals/headers/private/libroot/time_private.h =================================================================== --- haiku/branches/developer/bonefish/signals/headers/private/libroot/time_private.h (rev 0) +++ haiku/branches/developer/bonefish/signals/headers/private/libroot/time_private.h 2011-05-30 21:31:40 UTC (rev 41838) @@ -0,0 +1,52 @@ +/* + * Copyright 2011, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ +#ifndef _LIBROOT_TIME_PRIVATE_H +#define _LIBROOT_TIME_PRIVATE_H + + +#include <errno.h> +#include <sys/time.h> +#include <time.h> + +#include <SupportDefs.h> + +#include <new> + + +struct __timer_t { + int32 id; + thread_id thread; + clockid_t clockID; + + void SetTo(int32 id, thread_id thread, clockid_t clockID) + { + this->id = id; + this->thread = thread; + this->clockID = clockID; + } +}; + + +static inline void +bigtime_to_timespec(bigtime_t time, timespec& spec) +{ + spec.tv_sec = time / 1000000; + spec.tv_nsec = (time % 1000000) * 1000; +} + + +static inline bool +timespec_to_bigtime(const timespec& spec, bigtime_t& _time) +{ + if (spec.tv_nsec < 0 || spec.tv_nsec >= 1000000000) + return false; + + _time = (bigtime_t)spec.tv_sec * 1000000 + (spec.tv_nsec + 999) / 1000; + + return true; +} + + +#endif // _LIBROOT_TIME_PRIVATE_H Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/timer_support.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/timer_support.cpp 2011-05-30 21:17:10 UTC (rev 41837) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/timer_support.cpp 2011-05-30 21:31:40 UTC (rev 41838) @@ -17,36 +17,10 @@ #include <user_timer_defs.h> #include <libroot_private.h> +#include <time_private.h> -struct __timer_t { - int32 id; - thread_id thread; - clockid_t clockID; -}; - - static void -bigtime_to_timespec(bigtime_t time, timespec& spec) -{ - spec.tv_sec = time / 1000000; - spec.tv_nsec = (time % 1000000) * 1000; -} - - -static bool -timespec_to_bigtime(const timespec& spec, bigtime_t& _time) -{ - if (spec.tv_nsec < 0 || spec.tv_nsec >= 1000000000) - return false; - - _time = (bigtime_t)spec.tv_sec * 1000000 + spec.tv_nsec / 1000; - - return true; -} - - -static void info_to_itimerspec(const user_timer_info& info, itimerspec& spec, bigtime_t baseTime) { @@ -62,9 +36,10 @@ if (remainingTime <= 0) remainingTime = 1; bigtime_to_timespec(remainingTime, spec.it_value); - } else + } else { spec.it_value.tv_sec = 0; spec.it_value.tv_nsec = 0; + } } @@ -117,9 +92,7 @@ RETURN_AND_SET_ERRNO(timerID); // init the object members - timer->id = timerID; - timer->thread = -1; - timer->clockID = clockID; + timer->SetTo(timerID, -1, clockID); *_timer = timerDeleter.Detach(); return 0;