\begin{code}
#if defined(PROFILING) || defined(PAR) || defined(CONCURRENT)
+#if !defined(_AIX)
#define NON_POSIX_SOURCE /* time things on Solaris -- sigh */
#endif
+#endif
#include "rtsdefs.h"
#include <setjmp.h>
extern rtsBool TraceSparks, DelaySparks,
DeferGlobalUpdates;
-extern void RunParallelSystem PROTO((P_));
-extern void initParallelSystem(STG_NO_ARGS);
-extern void SynchroniseSystem(STG_NO_ARGS);
+void RunParallelSystem PROTO((P_));
+void initParallelSystem(STG_NO_ARGS);
+void SynchroniseSystem(STG_NO_ARGS);
-extern void SetTrace PROTO((W_ address, I_ level/*?*/));
+void SetTrace PROTO((W_ address, I_ level/*?*/));
#endif
-extern void *stgAllocForGMP PROTO((size_t));
-extern void *stgReallocForGMP PROTO ((void *, size_t, size_t));
-extern void stgDeallocForGMP PROTO ((void *, size_t));
+void *stgAllocForGMP PROTO((size_t));
+void *stgReallocForGMP PROTO ((void *, size_t, size_t));
+void stgDeallocForGMP PROTO ((void *, size_t));
/* NeXTs can't just reach out and touch "end", to use in
distinguishing things in static vs dynamic (malloc'd) memory.
int nPEs = 0; /* Number of PEs */
#endif
-int /* return type of "main" is defined by the C standard */
-main(int argc, char *argv[])
+\end{code}
+
+Setting up and initialising the run-time system:
+(used by main(), and people that don't allow Haskell
+to stay in control.)
+
+\begin{code}
+void
+initRTS(int argc, char *argv[])
{
#ifdef GRAN
int i;
if (*argv[0] == '-') { /* Look to see whether we're the Main Thread */
IAmMainThread = rtsTrue;
argv++; argc--; /* Strip off flag argument */
-/* fprintf(stderr, "I am Main Thread\n"); */
}
/*
* Grab the number of PEs out of the argument vector, and
what statsfile to use (if any); [if so, write the whole
cmd-line into it]
- This is unlikely to work well in parallel! KH.
*/
initRtsFlagsDefaults();
defaultsHook(); /* the one supplied does nothing;
initUserSignals();
#endif
+
+}
+
+int /* return type of "main" is defined by the C standard */
+main(int argc, char *argv[])
+{
+ initRTS(argc,argv);
+
#ifdef CONCURRENT
- AvailableStack = AvailableTSO = Prelude_Z91Z93_closure;
+ AvailableStack = AvailableTSO = PrelBase_Z91Z93_closure;
# if defined(GRAN) /* HWL */
/* Moved in here from ScheduleThreads, to handle a restart_main
(because of a signal) properly. */
for (i=0; i<RTSflags.GranFlags.proc; i++)
{
- RunnableThreadsHd[i] = RunnableThreadsTl[i] = Prelude_Z91Z93_closure;
- WaitThreadsHd[i] = WaitThreadsTl[i] = Prelude_Z91Z93_closure;
+ RunnableThreadsHd[i] = RunnableThreadsTl[i] = PrelBase_Z91Z93_closure;
+ WaitThreadsHd[i] = WaitThreadsTl[i] = PrelBase_Z91Z93_closure;
PendingSparksHd[i][REQUIRED_POOL] = PendingSparksHd[i][ADVISORY_POOL] =
PendingSparksTl[i][REQUIRED_POOL] = PendingSparksTl[i][ADVISORY_POOL] =
NULL;
}
# else
- RunnableThreadsHd = RunnableThreadsTl = Prelude_Z91Z93_closure;
- WaitingThreadsHd = WaitingThreadsTl = Prelude_Z91Z93_closure;
+ RunnableThreadsHd = RunnableThreadsTl = PrelBase_Z91Z93_closure;
+ WaitingThreadsHd = WaitingThreadsTl = PrelBase_Z91Z93_closure;
PendingSparksHd[REQUIRED_POOL] =
PendingSparksTl[REQUIRED_POOL] = PendingSparksBase[REQUIRED_POOL];
PendingSparksHd[ADVISORY_POOL] =
PendingSparksTl[ADVISORY_POOL] = PendingSparksBase[ADVISORY_POOL];
# endif
- CurrentTSO = Prelude_Z91Z93_closure;
+ CurrentTSO = PrelBase_Z91Z93_closure;
# ifdef PAR
RunParallelSystem(TopClosure);
# else
- STKO_LINK(MainStkO) = Prelude_Z91Z93_closure;
+ STKO_LINK(MainStkO) = PrelBase_Z91Z93_closure;
ScheduleThreads(TopClosure);
# endif /* PAR */
if (RTSflags.TickyFlags.showTickyStats) PrintTickyInfo();
#endif
+ /* Give the application a chance to do something sensible
+ on-exit
+ */
+ OnExitHook();
+
fflush(stdout);
/* This fflush is important, because: if "main" just returns,
then we will end up in pre-supplied exit code that will close