#include "RtsTypeable.h"
#include "Stable.h"
#include "Hpc.h"
+#include "FileLock.h"
#if defined(RTS_GTK_FRONTPANEL)
#include "FrontPanel.h"
argv++; argc--;
#endif
- /* Initialise the performance tracking library */
-#ifdef USE_PAPI
- {
- int ver;
- if ((ver = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
- if (ver > 0) {
- errorBelch("PAPI_library_init: wrong version: %x", ver);
- stg_exit(EXIT_FAILURE);
- } else {
- sysErrorBelch("PAPI_library_init");
- stg_exit(EXIT_FAILURE);
- }
- }
- }
-#ifdef THREADED_RTS
- {
- int err;
- if ((err = PAPI_thread_init(osThreadId)) < 0) {
- barf("PAPI_thread_init: %d",err);
- }
- }
-#endif
-#endif
-
/* Set the RTS flags to default values. */
initRtsFlagsDefaults();
setProgArgv(*argc,*argv);
}
+#ifdef USE_PAPI
+ papi_init();
+#endif
+
/* initTracing must be after setupRtsFlags() */
initTracing();
/* initialise the shared Typeable store */
initTypeableStore();
+ /* initialise file locking, if necessary */
+#if !defined(mingw32_HOST_OS)
+ initFileLocking();
+#endif
+
#if defined(DEBUG)
/* initialise thread label table (tso->char*) */
initThreadLabelTable();
initProfiling1();
/* start the virtual timer 'subsystem'. */
+ initTimer();
startTimer();
/* Initialise the stats department */
x86_init_fpu();
#endif
-#if defined(THREADED_RTS)
- ioManagerStart();
-#endif
-
/* Record initialization times */
stat_endInit();
}
{
bdescr *bd;
nat init_sp;
- Capability *cap = &MainCapability;
+ Capability *cap;
+
+ cap = rts_lock();
if (hs_init_count <= 0) {
barf("hs_add_root() must be called after hs_init()");
// This must be done after module initialisation.
// ToDo: make this work in the presence of multiple hs_add_root()s.
initProfiling2();
+
+ rts_unlock(cap);
+
+ // ditto.
+#if defined(THREADED_RTS)
+ ioManagerStart();
+#endif
}
/* ----------------------------------------------------------------------------
/* stop the ticker */
stopTimer();
+ exitTimer();
/* reset the standard file descriptors to blocking mode */
resetNonBlockingFd(0);
/* free shared Typeable store */
exitTypeableStore();
+ /* free file locking tables, if necessary */
+#if !defined(mingw32_HOST_OS)
+ freeFileLocking();
+#endif
+
/* free the stable pointer table */
exitStablePtrTable();
// Originally, this was in report_ccs_profiling(). Now, retainer
// profiling might tack some extra stuff on to the end of this file
// during endProfiling().
- fclose(prof_file);
+ if (prof_file != NULL) fclose(prof_file);
#endif
#if defined(TICKY_TICKY)