+ switch (rc) {
+ case Success:
+ return;
+ case Killed:
+ errorBelch("%s: uncaught exception",site);
+ stg_exit(EXIT_FAILURE);
+ case Interrupted:
+ errorBelch("%s: interrupted", site);
+ stg_exit(EXIT_FAILURE);
+ default:
+ errorBelch("%s: Return code (%d) not ok",(site),(rc));
+ stg_exit(EXIT_FAILURE);
+ }
+}
+
+void
+rts_lock()
+{
+#ifdef RTS_SUPPORTS_THREADS
+ 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)
+ waitForReturnCapability(&sched_mutex,&rtsApiCapability);
+#else
+ grabCapability(&rtsApiCapability);
+#endif
+}
+
+void
+rts_unlock()
+{
+#ifdef RTS_SUPPORTS_THREADS
+ if (rtsApiCapability) {
+ releaseCapability(rtsApiCapability);
+ }
+ rtsApiCapability = NULL;
+ RELEASE_LOCK(&sched_mutex);
+#endif