{
Task *task;
- ASSERT(cap->running_task != NULL && myTask() == cap->running_task);
-
task = cap->running_task;
- cap->running_task = NULL;
- ASSERT(task->id == osThreadId());
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
+
+ cap->running_task = NULL;
// Check to see whether a worker thread can be given
// the go-ahead to return the result of an external call..
}
- ASSERT(cap->running_task == task);
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
IF_DEBUG(scheduler,
sched_belch("returning; got capability %d", cap->no));
}
*pCap = cap;
+
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
+
return;
}
#endif
}; // typedef Capability, defined in RtsAPI.h
+
+// These properties should be true when a Task is holding a Capability
+#define ASSERT_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(task->id == osThreadId());
+
+
// Converts a *StgRegTable into a *Capability.
//
INLINE_HEADER Capability *
Task *task;
task = cap->running_task;
- ASSERT(task == myTask());
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
// slightly delicate ordering of operations below, pay attention!
// thread for a bit, even if there are others banging at the
// door.
first = rtsFalse;
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
} else {
// Yield the capability to higher-priority tasks if necessary.
yieldCapability(&cap, task);
}
#endif
- ASSERT(cap->running_task == task);
- ASSERT(task->cap == cap);
- ASSERT(myTask() == task);
-
// Check whether we have re-entered the RTS from Haskell without
// going via suspendThread()/resumeThread (i.e. a 'safe' foreign
// call).
if (ret == ThreadBlocked) continue;
#endif
- ASSERT(cap->running_task == task);
- ASSERT(task->cap == cap);
- ASSERT(myTask() == task);
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
// The TSO might have moved, eg. if it re-entered the RTS and a GC
// happened. So find the new location:
cap = schedule(cap,task);
ASSERT(task->stat != NoStatus);
- ASSERT(cap->running_task == task);
- ASSERT(task->cap == cap);
+ ASSERT_CAPABILITY_INVARIANTS(cap,task);
IF_DEBUG(scheduler, sched_belch("bound thread (%d) finished", task->tso->id));
return cap;