+pthread_once_t pthread_pause_once_ctrl = PTHREAD_ONCE_INIT;
+
+void pthread_pause_once(void) {
+ sem_init(&pthread_pause_sem, 0, 1);
+}
+
+#define pthread_pause_init() (pthread_once(&pthread_pause_once_ctrl, &pthread_pause_once))
+
+#define NSEC_PER_SEC (1000*1000*1000)
+// timespec_normalise() from https://github.com/solemnwarning/timespec/
+struct timespec timespec_normalise(struct timespec ts)
+{
+ while(ts.tv_nsec >= NSEC_PER_SEC) {
+ ++(ts.tv_sec); ts.tv_nsec -= NSEC_PER_SEC;
+ }
+ while(ts.tv_nsec <= -NSEC_PER_SEC) {
+ --(ts.tv_sec); ts.tv_nsec += NSEC_PER_SEC;
+ }
+ if(ts.tv_nsec < 0) { // Negative nanoseconds isn't valid according to POSIX.
+ --(ts.tv_sec); ts.tv_nsec = (NSEC_PER_SEC + ts.tv_nsec);
+ }
+ return ts;
+}