X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FRtsStartup.c;h=070275b534f7825efae60ae1cabd882e59954e30;hb=29d9667f3bed7bdfc1839411cd40aef09d4b0fc1;hp=4f84468b0a8a61afc18ee863b54a0a5f6bd5ce85;hpb=1d026619ef5f098a0349ba2fa1b29d5697718bad;p=ghc-hetmet.git diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c index 4f84468..070275b 100644 --- a/rts/RtsStartup.c +++ b/rts/RtsStartup.c @@ -167,30 +167,6 @@ hs_init(int *argc, char **argv[]) 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(); @@ -205,6 +181,10 @@ hs_init(int *argc, char **argv[]) setProgArgv(*argc,*argv); } +#ifdef USE_PAPI + papi_init(); +#endif + /* initTracing must be after setupRtsFlags() */ initTracing(); @@ -281,10 +261,6 @@ hs_init(int *argc, char **argv[]) x86_init_fpu(); #endif -#if defined(THREADED_RTS) - ioManagerStart(); -#endif - /* Record initialization times */ stat_endInit(); } @@ -334,7 +310,9 @@ hs_add_root(void (*init_root)(void)) { 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()"); @@ -360,6 +338,13 @@ hs_add_root(void (*init_root)(void)) // 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 } /* ---------------------------------------------------------------------------- @@ -498,7 +483,7 @@ hs_exit_(rtsBool wait_foreign) // 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)