- //
- // Go through the list of main threads and wake up any
- // clients whose computations have finished. ToDo: this
- // should be done more efficiently without a linear scan
- // of the main threads list, somehow...
- //
-#if defined(RTS_SUPPORTS_THREADS)
- {
- StgMainThread *m, **prev;
- prev = &main_threads;
- for (m = main_threads; m != NULL; prev = &m->link, m = m->link) {
- if (m->tso->what_next == ThreadComplete
- || m->tso->what_next == ThreadKilled) {
- if (m == mainThread) {
- if (m->tso->what_next == ThreadComplete) {
- if (m->ret) {
- // NOTE: return val is tso->sp[1]
- // (see StgStartup.hc)
- *(m->ret) = (StgClosure *)m->tso->sp[1];
- }
- m->stat = Success;
- } else {
- if (m->ret) {
- *(m->ret) = NULL;
- }
- if (was_interrupted) {
- m->stat = Interrupted;
- } else {
- m->stat = Killed;
- }
- }
- *prev = m->link;
-#ifdef DEBUG
- removeThreadLabel((StgWord)m->tso->id);
-#endif
- releaseCapability(cap);
- return;
- } else {
- // The current OS thread can not handle the fact that
- // the Haskell thread "m" has ended. "m" is bound;
- // the scheduler loop in its bound OS thread has to
- // return, so let's pass the capability directly to
- // that thread.
- passCapability(&m->bound_thread_cond);
- continue;
- }
- }
- }
- }
-
-#else /* not threaded */
-
-# if defined(PAR)
- /* in GUM do this only on the Main PE */
- if (IAmMainThread)
-# endif
- /* If our main thread has finished or been killed, return.
- */
- {
- StgMainThread *m = main_threads;
- if (m->tso->what_next == ThreadComplete
- || m->tso->what_next == ThreadKilled) {
-#ifdef DEBUG
- removeThreadLabel((StgWord)m->tso->id);
-#endif
- main_threads = main_threads->link;
- if (m->tso->what_next == ThreadComplete) {
- // We finished successfully, fill in the return value
- // NOTE: return val is tso->sp[1] (see StgStartup.hc)
- if (m->ret) { *(m->ret) = (StgClosure *)m->tso->sp[1]; };
- m->stat = Success;
- return;
- } else {
- if (m->ret) { *(m->ret) = NULL; };
- if (was_interrupted) {
- m->stat = Interrupted;
- } else {
- m->stat = Killed;
- }
- return;
- }
- }
- }
-#endif
-
-