#include "Stable.h"
#include "Hpc.h"
#include "FileLock.h"
+#include "EventLog.h"
#if defined(RTS_GTK_FRONTPANEL)
#include "FrontPanel.h"
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#if USE_PAPI
#include "Papi.h"
#endif
/* initTracing must be after setupRtsFlags() */
+#ifdef DEBUG
initTracing();
+#endif
#if defined(PAR)
/* NB: this really must be done after processing the RTS flags */
/* 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();
initProfiling1();
+#ifdef EVENTLOG
+ if (RtsFlags.EventLogFlags.doEventLogging) {
+ initEventLogging();
+ }
+#endif
+
/* start the virtual timer 'subsystem'. */
initTimer();
startTimer();
/* start timing the shutdown */
stat_startExit();
-#if defined(RTS_USER_SIGNALS)
- if (RtsFlags.MiscFlags.install_signal_handlers) {
- freeSignalHandlers();
- }
-#endif
+ OnExitHook();
#if defined(THREADED_RTS)
ioManagerDie();
/* stop all running tasks */
exitScheduler(wait_foreign);
+
+ /* run C finalizers for all active weak pointers */
+ runAllCFinalizers(weak_ptr_list);
+#if defined(RTS_USER_SIGNALS)
+ if (RtsFlags.MiscFlags.install_signal_handlers) {
+ freeSignalHandlers();
+ }
+#endif
+
#if defined(GRAN)
/* end_gr_simulation prints global stats if requested -- HWL */
if (!RtsFlags.GranFlags.GranSimStats.Suppressed)
PAR_TICKY_PAR_END();
#endif
+ // uninstall signal handlers
+ resetDefaultHandlers();
+
/* stop timing the shutdown, we're about to print stats */
stat_endExit();
if (prof_file != NULL) fclose(prof_file);
#endif
+#ifdef EVENTLOG
+ if (RtsFlags.EventLogFlags.doEventLogging) {
+ endEventLogging();
+ freeEventLogging();
+ }
+#endif
+
#if defined(TICKY_TICKY)
if (RtsFlags.TickyFlags.showTickyStats) PrintTickyInfo();
#endif
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
*/