remove empty dir
[ghc-hetmet.git] / ghc / rts / Capability.h
index 2a04e41..a2551d0 100644 (file)
@@ -1,19 +1,19 @@
 /* ---------------------------------------------------------------------------
  *
- * (c) The GHC Team, 2001-2003
+ * (c) The GHC Team, 2001-2006
  *
  * Capabilities
  *
  * The notion of a capability is used when operating in multi-threaded
- * environments (which the SMP and Threads builds of the RTS do), to
+ * environments (which the THREADED_RTS build of the RTS does), to
  * hold all the state an OS thread/task needs to run Haskell code:
  * its STG registers, a pointer to its  TSO, a nursery etc. During
  * STG execution, a pointer to the capabilitity is kept in a 
  * register (BaseReg).
  *
- * Only in an SMP build will there be multiple capabilities, the threaded
- * RTS and other non-threaded builds, there is one global capability,
- * namely MainRegTable.
+ * Only in an THREADED_RTS build will there be multiple capabilities,
+ * in the non-threaded builds there is one global capability, namely
+ * MainCapability.
  *
  * This header file contains the functions for working with capabilities.
  * (the main, and only, consumer of this interface is the scheduler).
@@ -70,7 +70,7 @@ struct Capability_ {
     // Worker Tasks waiting in the wings.  Singly-linked.
     Task *spare_workers;
 
-    // This lock protects running_task and returning_tasks_{hd,tl}.
+    // This lock protects running_task, returning_tasks_{hd,tl}, wakeup_queue.
     Mutex lock;
 
     // Tasks waiting to return from a foreign call, or waiting to make
@@ -80,6 +80,12 @@ struct Capability_ {
     // check whether it is NULL without taking the lock, however.
     Task *returning_tasks_hd; // Singly-linked, with head/tail
     Task *returning_tasks_tl;
+
+    // A list of threads to append to this Capability's run queue at
+    // the earliest opportunity.  These are threads that have been
+    // woken up by another Capability.
+    StgTSO *wakeup_queue_hd;
+    StgTSO *wakeup_queue_tl;
 #endif
 
     // Per-capability STM-related data
@@ -97,12 +103,20 @@ struct Capability_ {
 #endif
 
 // These properties should be true when a Task is holding a Capability
-#define ASSERT_CAPABILITY_INVARIANTS(cap,task)                         \
+#define ASSERT_FULL_CAPABILITY_INVARIANTS(cap,task)                    \
   ASSERT(cap->running_task != NULL && cap->running_task == task);      \
   ASSERT(task->cap == cap);                                            \
-  ASSERT(cap->run_queue_hd == END_TSO_QUEUE ?                          \
-           cap->run_queue_tl == END_TSO_QUEUE : 1);                    \
-  ASSERT(myTask() == task);                                            \
+  ASSERT_PARTIAL_CAPABILITY_INVARIANTS(cap,task)
+
+// Sometimes a Task holds a Capability, but the Task is not associated
+// with that Capability (ie. task->cap != cap).  This happens when
+// (a) a Task holds multiple Capabilities, and (b) when the current
+// Task is bound, its thread has just blocked, and it may have been
+// moved to another Capability.
+#define ASSERT_PARTIAL_CAPABILITY_INVARIANTS(cap,task) \
+  ASSERT(cap->run_queue_hd == END_TSO_QUEUE ?          \
+           cap->run_queue_tl == END_TSO_QUEUE : 1);    \
+  ASSERT(myTask() == task);                            \
   ASSERT_TASK_ID(task);
 
 // Converts a *StgRegTable into a *Capability.
@@ -132,8 +146,8 @@ INLINE_HEADER void releaseCapability  (Capability* cap STG_UNUSED) {};
 INLINE_HEADER void releaseCapability_ (Capability* cap STG_UNUSED) {};
 #endif
 
-#if !IN_STG_CODE && !defined(SMP)
-// for non-SMP, we have one global capability
+#if !IN_STG_CODE
+// one global capability
 extern Capability MainCapability; 
 #endif
 
@@ -181,6 +195,11 @@ void yieldCapability (Capability** pCap, Task *task);
 //
 void waitForCapability (Task *task, Mutex *mutex, Capability **pCap);
 
+// Wakes up a thread on a Capability (probably a different Capability
+// from the one held by the current Task).
+//
+void wakeupThreadOnCapability (Capability *cap, StgTSO *tso);
+
 // Wakes up a worker thread on just one Capability, used when we
 // need to service some global event.
 //