+//@cindex PUSH_ON_RUN_QUEUE
+/* Push a thread on the beginning of the run queue. Used for
+ * newly awakened threads, so they get run as soon as possible.
+ */
+#define PUSH_ON_RUN_QUEUE(tso) \
+ tso->link = run_queue_hd; \
+ run_queue_hd = tso; \
+ if (run_queue_tl == END_TSO_QUEUE) { \
+ run_queue_tl = tso; \
+ }
+
+//@cindex POP_RUN_QUEUE
+/* Pop the first thread off the runnable queue.
+ */
+#define POP_RUN_QUEUE() \
+ ({ StgTSO *t = run_queue_hd; \
+ if (t != END_TSO_QUEUE) { \
+ run_queue_hd = t->link; \
+ t->link = END_TSO_QUEUE; \
+ if (run_queue_hd == END_TSO_QUEUE) { \
+ run_queue_tl = END_TSO_QUEUE; \
+ } \
+ } \
+ t; \
+ })
+
+//@cindex APPEND_TO_BLOCKED_QUEUE
+/* Add a thread to the end of the blocked queue.
+ */
+#define APPEND_TO_BLOCKED_QUEUE(tso) \
+ ASSERT(tso->link == END_TSO_QUEUE); \
+ if (blocked_queue_hd == END_TSO_QUEUE) { \
+ blocked_queue_hd = tso; \
+ } else { \
+ blocked_queue_tl->link = tso; \
+ } \
+ blocked_queue_tl = tso;
+
+//@cindex THREAD_RUNNABLE
+/* Signal that a runnable thread has become available, in
+ * case there are any waiting tasks to execute it.
+ */
+#ifdef SMP
+#define THREAD_RUNNABLE() \
+ if (free_capabilities != NULL) { \
+ pthread_cond_signal(&thread_ready_cond); \
+ } \
+ context_switch = 1;
+#else
+#define THREAD_RUNNABLE() /* nothing */
+#endif
+
+//@node Index, , Some convenient macros
+//@subsection Index
+
+//@index
+//* APPEND_TO_BLOCKED_QUEUE:: @cindex\s-+APPEND_TO_BLOCKED_QUEUE
+//* APPEND_TO_RUN_QUEUE:: @cindex\s-+APPEND_TO_RUN_QUEUE
+//* Capability:: @cindex\s-+Capability
+//* POP_RUN_QUEUE :: @cindex\s-+POP_RUN_QUEUE
+//* PUSH_ON_RUN_QUEUE:: @cindex\s-+PUSH_ON_RUN_QUEUE
+//* THREAD_RUNNABLE:: @cindex\s-+THREAD_RUNNABLE
+//* awaitEvent:: @cindex\s-+awaitEvent
+//* awakenBlockedQueue:: @cindex\s-+awakenBlockedQueue
+//* awaken_blocked_queue:: @cindex\s-+awaken_blocked_queue
+//* context_switch:: @cindex\s-+context_switch
+//* exitScheduler:: @cindex\s-+exitScheduler
+//* gc_pending_cond:: @cindex\s-+gc_pending_cond
+//* initScheduler:: @cindex\s-+initScheduler
+//* raiseAsync:: @cindex\s-+raiseAsync
+//* sched_mutex:: @cindex\s-+sched_mutex
+//* startTasks:: @cindex\s-+startTasks
+//* task_info:: @cindex\s-+task_info
+//* thread_ready_cond:: @cindex\s-+thread_ready_cond
+//* unblockOne:: @cindex\s-+unblockOne
+//@end index