Main.c 1.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
/* -----------------------------------------------------------------------------
 * $Id: Main.c,v 1.2 1998/12/02 13:28:30 simonm Exp $
 *
 * Main function for a standalone Haskell program.
 *
 * ---------------------------------------------------------------------------*/

#include "Rts.h"
#include "RtsAPI.h"
#include "Schedule.h"  /* for MainTSO */
#include "RtsUtils.h"

#ifdef DEBUG
#include "RtsFlags.h"  /* for debugging flags */
#include "Printer.h"   /* for printing        */
#endif

#ifdef INTERPRETER
#include "Assembler.h"
#endif

#ifdef PAR
#include "ParInit.h"
#include "Parallel.h"
#include "LLC.h"
#endif

/* Hack: we assume that we're building a batch-mode system unless 
 * INTERPRETER is set
 */
#ifndef INTERPRETER /* Hack */
int main(int argc, char *argv[])
{
    SchedulerStatus status;
    startupHaskell(argc,argv);

#ifndef PAR
    MainTSO = createIOThread(BLOCK_SIZE_W,(StgClosure *)&mainIO_closure);
    status = schedule(MainTSO,NULL);
#else
    if (IAmMainThread == rtsTrue) {
    /*Just to show we're alive */
      fprintf(stderr, "Main Thread Started ...\n");
     
      MainTSO = createIOThread(BLOCK_SIZE_W,(StgClosure *)&mainIO_closure);
      status = schedule(MainTSO,NULL);
    } else {
      WaitForPEOp(PP_FINISH,SysManTask);
      exit(EXIT_SUCCESS);
    }
#endif /* PAR */
    switch (status) {
    case AllBlocked:
      barf("Scheduler stopped, all threads blocked");
    case Deadlock:
      shutdownHaskell();
      barf("No threads to run!  Deadlock?");
    case Killed:
      belch("%s: warning: main thread killed", prog_argv[0]);
    case Success:
    case Interrupted:
      /* carry on */
    }
    shutdownHaskell();
    stg_exit(EXIT_SUCCESS);
}
#endif /* BATCH_MODE */