+/**
+ * Park the current thread for the specified amount of time or until a
+ * specified deadline.
+ *
+ * @param absolute Is the time in nanos a deadline or a duration?
+ * @param nanos Nanoseconds to park (absolute=false)
+ * or deadline in milliseconds (absolute=true)
+ */
+void threads_park(bool absolute, int64_t nanos)
+{
+ threadobject *t;
+ struct timespec wakeupTime;
+
+ t = thread_get_current();
+
+ if (absolute) {
+ wakeupTime.tv_nsec = 0;
+ wakeupTime.tv_sec = nanos / 1000; /* milliseconds */
+ }
+ else
+ threads_calc_absolute_time(&wakeupTime, nanos / 1000000, nanos % 1000000);
+
+ threads_wait_with_timeout(t, &wakeupTime, true);
+}
+
+/**
+ * Unpark the specified thread.
+ *
+ * @param t The thread to unpark.
+ */
+void threads_unpark(threadobject *t)
+{
+ t->waitmutex->lock();
+
+ t->waitcond->signal();
+
+ t->park_permit = true;
+
+ t->waitmutex->unlock();
+}
+