#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#if USE_PAPI
#include "Papi.h"
return;
}
-#if defined(DEBUG)
- /* Start off by initialising the allocator debugging so we can
- * use it anywhere */
- initAllocator();
-#endif
+ /* Initialise the stats department, phase 0 */
+ initStats0();
/* Next we do is grab the start time...just in case we're
* collecting timing statistics.
*/
stat_startInit();
+#if defined(DEBUG)
+ /* Start off by initialising the allocator debugging so we can
+ * use it anywhere */
+ initAllocator();
+#endif
+
#ifdef PAR
/*
* The parallel system needs to be initialised and synchronised before
setProgArgv(*argc,*argv);
}
+ /* Initialise the stats department, phase 1 */
+ initStats1();
+
#ifdef USE_PAPI
papi_init();
#endif
/* initialise the stable pointer table */
initStablePtrTable();
+ /* Add some GC roots for things in the base package that the RTS
+ * knows about. We don't know whether these turn out to be CAFs
+ * or refer to CAFs, but we have to assume that they might.
+ */
+ getStablePtr((StgPtr)base_GHCziTopHandler_runIO_closure);
+ getStablePtr((StgPtr)base_GHCziTopHandler_runNonIO_closure);
+ getStablePtr((StgPtr)stackOverflow_closure);
+ getStablePtr((StgPtr)heapOverflow_closure);
+ getStablePtr((StgPtr)runFinalizerBatch_closure);
+ getStablePtr((StgPtr)unpackCString_closure);
+ getStablePtr((StgPtr)blockedOnDeadMVar_closure);
+ getStablePtr((StgPtr)nonTermination_closure);
+ getStablePtr((StgPtr)blockedIndefinitely_closure);
+
/* initialise the shared Typeable store */
initTypeableStore();
initTimer();
startTimer();
- /* Initialise the stats department */
- initStats();
-
#if defined(RTS_USER_SIGNALS)
if (RtsFlags.MiscFlags.install_signal_handlers) {
/* Initialise the user signal handler set */
/* start timing the shutdown */
stat_startExit();
+ OnExitHook();
+
#if defined(RTS_USER_SIGNALS)
if (RtsFlags.MiscFlags.install_signal_handlers) {
freeSignalHandlers();
/* stop all running tasks */
exitScheduler(wait_foreign);
+
+ /* run C finalizers for all active weak pointers */
+ runAllCFinalizers(weak_ptr_list);
#if defined(GRAN)
/* end_gr_simulation prints global stats if requested -- HWL */
PAR_TICKY_PAR_END();
#endif
+ // uninstall signal handlers
+ resetDefaultHandlers();
+
/* stop timing the shutdown, we're about to print stats */
stat_endExit();
void
shutdownHaskellAndExit(int n)
{
- if (hs_init_count == 1) {
- OnExitHook();
- hs_exit_(rtsFalse);
- // we're about to exit(), no need to wait for foreign calls to return.
+ // we're about to exit(), no need to wait for foreign calls to return.
+ hs_exit_(rtsFalse);
+
+ if (hs_init_count == 0) {
#if defined(PAR)
/* really exit (stg_exit() would call shutdownParallelSystem() again) */
exit(n);
}
}
+#ifndef mingw32_HOST_OS
+void
+shutdownHaskellAndSignal(int sig)
+{
+ hs_exit_(rtsFalse);
+ kill(getpid(),sig);
+}
+#endif
+
/*
* called from STG-land to exit the program
*/