# define vlc_clock_setup() (void)0
#endif /* _POSIX_TIMERS */
+static struct timespec mtime_to_ts (mtime_t date)
+{
+ lldiv_t d = lldiv (date, CLOCK_FREQ);
+ struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
+
+ return ts;
+}
+
/**
* Print a backtrace to the standard error for debugging purpose.
*/
deadline -= base;
if (deadline < 0)
deadline = 0;
- lldiv_t d = lldiv( deadline, CLOCK_FREQ );
- struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
+ struct timespec ts = mtime_to_ts (deadline);
int val = pthread_cond_timedwait_relative_np(p_condvar, p_mutex, &ts);
#else
- lldiv_t d = lldiv( deadline, CLOCK_FREQ );
- struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
+ struct timespec ts = mtime_to_ts (deadline);
int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts);
#endif
if (val != ETIMEDOUT)
* do not even bother the system timer. */
deadline -= vlc_clock_prec;
- lldiv_t d = lldiv (deadline, 1000000);
- struct timespec ts = { d.quot, d.rem * 1000 };
+ struct timespec ts = mtime_to_ts (deadline);
while (clock_nanosleep (vlc_clock_id, TIMER_ABSTIME, &ts, NULL) == EINTR);
*/
void msleep (mtime_t delay)
{
- vlc_clock_setup ();
-
- lldiv_t d = lldiv (delay, 1000000);
- struct timespec ts = { d.quot, d.rem * 1000 };
+ struct timespec ts = mtime_to_ts (delay);
+ vlc_clock_setup ();
#if (_POSIX_TIMERS > 0)
while (clock_nanosleep (vlc_clock_id, 0, &ts, &ts) == EINTR);