+# ifdef mingw32_TARGET_OS
+# include <windows.h>
+# endif
+
+/* last timestamp */
+nat timestamp = 0;
+
+/* keep track of the number of ticks since we last called
+ * gettimeofday(), to avoid having to call it every time we need
+ * a timestamp.
+ */
+nat ticks_since_timestamp = 0;
+
+/* There's a clever trick here to avoid problems when the time wraps
+ * around. Since our maximum delay is smaller than 31 bits of ticks
+ * (it's actually 31 bits of microseconds), we can safely check
+ * whether a timer has expired even if our timer will wrap around
+ * before the target is reached, using the following formula:
+ *
+ * (int)((uint)current_time - (uint)target_time) < 0
+ *
+ * if this is true, then our time has expired.
+ * (idea due to Andy Gill).
+ */
+rtsBool
+wakeUpSleepingThreads(nat ticks)
+{
+ StgTSO *tso;
+ rtsBool flag = rtsFalse;
+
+ while (sleeping_queue != END_TSO_QUEUE &&
+ (int)(ticks - sleeping_queue->block_info.target) > 0) {
+ tso = sleeping_queue;
+ sleeping_queue = tso->link;
+ tso->why_blocked = NotBlocked;
+ tso->link = END_TSO_QUEUE;
+ IF_DEBUG(scheduler,belch("Waking up sleeping thread %d\n", tso->id));
+ PUSH_ON_RUN_QUEUE(tso);
+ flag = rtsTrue;
+ }
+ return flag;
+}