+#ifndef CAPABILITY_H
+#define CAPABILITY_H
+
+#include "RtsFlags.h"
+#include "Task.h"
+
+struct Capability_ {
+ // State required by the STG virtual machine when running Haskell
+ // code. During STG execution, the BaseReg register always points
+ // to the StgRegTable of the current Capability (&cap->r).
+ StgFunTable f;
+ StgRegTable r;
+
+ nat no; // capability number.
+
+ // The Task currently holding this Capability. This task has
+ // exclusive access to the contents of this Capability (apart from
+ // returning_tasks_hd/returning_tasks_tl).
+ // Locks required: cap->lock.
+ Task *running_task;
+
+ // true if this Capability is running Haskell code, used for
+ // catching unsafe call-ins.
+ rtsBool in_haskell;
+
+ // The run queue. The Task owning this Capability has exclusive
+ // access to its run queue, so can wake up threads without
+ // taking a lock, and the common path through the scheduler is
+ // also lock-free.
+ StgTSO *run_queue_hd;
+ StgTSO *run_queue_tl;
+
+ // Tasks currently making safe foreign calls. Doubly-linked.
+ // When returning, a task first acquires the Capability before
+ // removing itself from this list, so that the GC can find all
+ // the suspended TSOs easily. Hence, when migrating a Task from
+ // the returning_tasks list, we must also migrate its entry from
+ // this list.
+ Task *suspended_ccalling_tasks;
+
+#if defined(THREADED_RTS)
+ // Worker Tasks waiting in the wings. Singly-linked.
+ Task *spare_workers;
+
+ // This lock protects running_task and returning_tasks_{hd,tl}.
+ Mutex lock;
+
+ // Tasks waiting to return from a foreign call, or waiting to make
+ // a new call-in using this Capability (NULL if empty).
+ // NB. this field needs to be modified by tasks other than the
+ // running_task, so it requires cap->lock to modify. A task can
+ // check whether it is NULL without taking the lock, however.
+ Task *returning_tasks_hd; // Singly-linked, with head/tail
+ Task *returning_tasks_tl;
+#endif
+}; // typedef Capability, defined in RtsAPI.h