+void
+rts_checkSchedStatus ( char* site, SchedulerStatus rc )
+{
+ switch (rc) {
+ case Success:
+ return;
+ case Killed:
+ prog_belch("%s: uncaught exception",site);
+ stg_exit(EXIT_FAILURE);
+ case Interrupted:
+ prog_belch("%s: interrupted", site);
+ stg_exit(EXIT_FAILURE);
+ default:
+ prog_belch("%s: Return code (%d) not ok",(site),(rc));
+ stg_exit(EXIT_FAILURE);
+ }
+}
+
+#ifdef RTS_SUPPORTS_THREADS
+void
+rts_lock()
+{
+ Capability *cap;
+ ACQUIRE_LOCK(&sched_mutex);
+
+ // we request to get the capability immediately, in order to
+ // a) stop other threads from using allocate()
+ // b) wake the current worker thread from awaitEvent()
+ // (so that a thread started by rts_eval* will start immediately)
+ grabReturnCapability(&sched_mutex,&cap);
+
+ // now that we have the capability, we don't need it anymore
+ // (other threads will continue to run as soon as we release the sched_mutex)
+ releaseCapability(cap);
+
+ // In the RTS hasn't been entered yet,
+ // start a RTS task.
+ // If there is already a task available (waiting for the work capability),
+ // this will do nothing.
+ startSchedulerTask();
+}
+
+void
+rts_unlock()
+{
+ RELEASE_LOCK(&sched_mutex);