- struct timeval current_timeval;
- gettimeofday(¤t_timeval, NULL);
- struct timespec ts = {interval - 1 - (current_timeval.tv_sec % interval), (10e5 - current_timeval.tv_usec) * 1000};
- nanosleep(&ts, NULL);
+ struct timespec ts;
+#if defined(__APPLE__)
+ gettimeofday(&tv, NULL);
+ ts.tv_sec = tv.tv_sec;
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+ ts.tv_sec += interval - (ts.tv_sec % interval);
+ ts.tv_nsec = 0;
+
+ /* Sleep to absolute time 'ts', unless the condition
+ * 'i3status_sleep_cond' is signaled from another thread */
+ pthread_cond_timedwait(&i3status_sleep_cond, &i3status_sleep_mutex, &ts);