- ToDo: no support for two-space collection at the moment???
- -------------------------------------------------------------------------- */
-
-/* -----------------------------------------------------------------------------
- * waitThread is the external interface for running a new computation
- * and waiting for the result.
- *
- * In the non-SMP case, we create a new main thread, push it on the
- * main-thread stack, and invoke the scheduler to run it. The
- * scheduler will return when the top main thread on the stack has
- * completed or died, and fill in the necessary fields of the
- * main_thread structure.
- *
- * In the SMP case, we create a main thread as before, but we then
- * create a new condition variable and sleep on it. When our new
- * main thread has completed, we'll be woken up and the status/result
- * will be in the main_thread struct.
- * -------------------------------------------------------------------------- */
-
-SchedulerStatus
-waitThread(StgTSO *tso, /*out*/StgClosure **ret)
-{
- StgMainThread *m;
- SchedulerStatus stat;
-
- ACQUIRE_LOCK(&sched_mutex);
-
- m = stgMallocBytes(sizeof(StgMainThread), "waitThread");
-
- m->tso = tso;
- m->ret = ret;
- m->stat = NoStatus;
-#ifdef SMP
- pthread_cond_init(&m->wakeup, NULL);
-#endif
-
- m->link = main_threads;
- main_threads = m;
-
- IF_DEBUG(scheduler, fprintf(stderr, "scheduler: new main thread (%d)\n",
- m->tso->id));
-
-#ifdef SMP
- do {
- pthread_cond_wait(&m->wakeup, &sched_mutex);
- } while (m->stat == NoStatus);
-#elif defined(GRAN)
- /* GranSim specific init */
- CurrentTSO = m->tso; // the TSO to run
- procStatus[MainProc] = Busy; // status of main PE
- CurrentProc = MainProc; // PE to run it on
-
- schedule();
-#else
- schedule();
- ASSERT(m->stat != NoStatus);
-#endif
-
- stat = m->stat;
-
-#ifdef SMP
- pthread_cond_destroy(&m->wakeup);
-#endif
-
- IF_DEBUG(scheduler, fprintf(stderr, "scheduler: main thread (%d) finished\n",
- m->tso->id));
- free(m);
-
- RELEASE_LOCK(&sched_mutex);
-
- return stat;
-}
-
-//@node Run queue code, Garbage Collextion Routines, Suspend and Resume, Main scheduling code
-//@subsection Run queue code
-
-#if 0
-/*
- NB: In GranSim we have many run queues; run_queue_hd is actually a macro
- unfolding to run_queue_hds[CurrentProc], thus CurrentProc is an
- implicit global variable that has to be correct when calling these
- fcts -- HWL
-*/
-
-/* Put the new thread on the head of the runnable queue.
- * The caller of createThread better push an appropriate closure
- * on this thread's stack before the scheduler is invoked.
- */
-static /* inline */ void
-add_to_run_queue(tso)
-StgTSO* tso;
-{
- ASSERT(tso!=run_queue_hd && tso!=run_queue_tl);
- tso->link = run_queue_hd;
- run_queue_hd = tso;
- if (run_queue_tl == END_TSO_QUEUE) {
- run_queue_tl = tso;
- }
-}