+#ifdef RTS_USER_SIGNALS
+#define UNUSED_IF_NOT_THREADS
+#else
+#define UNUSED_IF_NOT_THREADS STG_UNUSED
+#endif
+
+
+STATIC_INLINE rtsBool
+globalWorkToDo (void)
+{
+ return blackholes_need_checking
+ || interrupted
+#if defined(RTS_USER_SIGNALS)
+ || signals_pending()
+#endif
+ ;
+}
+
+#if defined(THREADED_RTS)
+STATIC_INLINE rtsBool
+anyWorkForMe( Capability *cap, Task *task )
+{
+ // If the run queue is not empty, then we only wake up the guy who
+ // can run the thread at the head, even if there is some other
+ // reason for this task to run (eg. interrupted=rtsTrue).
+ if (!emptyRunQueue(cap)) {
+ if (cap->run_queue_hd->bound == NULL) {
+ return (task->tso == NULL);
+ } else {
+ return (cap->run_queue_hd->bound == task);
+ }
+ }
+ return globalWorkToDo();
+}
+#endif
+
+/* -----------------------------------------------------------------------------
+ * Manage the returning_tasks lists.
+ *
+ * These functions require cap->lock
+ * -------------------------------------------------------------------------- */
+
+#if defined(THREADED_RTS)
+STATIC_INLINE void
+newReturningTask (Capability *cap, Task *task)
+{
+ ASSERT_LOCK_HELD(&cap->lock);
+ ASSERT(task->return_link == NULL);
+ if (cap->returning_tasks_hd) {
+ ASSERT(cap->returning_tasks_tl->return_link == NULL);
+ cap->returning_tasks_tl->return_link = task;
+ } else {
+ cap->returning_tasks_hd = task;
+ }
+ cap->returning_tasks_tl = task;
+}
+
+STATIC_INLINE Task *
+popReturningTask (Capability *cap)
+{
+ ASSERT_LOCK_HELD(&cap->lock);
+ Task *task;
+ task = cap->returning_tasks_hd;
+ ASSERT(task);
+ cap->returning_tasks_hd = task->return_link;
+ if (!cap->returning_tasks_hd) {
+ cap->returning_tasks_tl = NULL;
+ }
+ task->return_link = NULL;
+ return task;
+}
+#endif
+