Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 459 lines (364 sloc) 10.668 kB
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
1 /* -----------------------------------------------------------------------------
7f309f1 [project @ 1999-02-05 16:02:18 by simonm]
simonm authored
2 *
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
3 * (c) The GHC Team, 1998-2002
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
4 *
5 * Main function for a standalone Haskell program.
6 *
7 * ---------------------------------------------------------------------------*/
8
fe07f05 Addition of PAPI to RTS
mrchebas@gmail.com authored
9 // PAPI uses caddr_t, which is not POSIX
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
10 #ifndef USE_PAPI
11 #include "PosixSource.h"
12 #endif
fe07f05 Addition of PAPI to RTS
mrchebas@gmail.com authored
13
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
14 #include "Rts.h"
15 #include "RtsAPI.h"
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
16 #include "HsFFI.h"
17
18 #include "sm/Storage.h"
5463b55 @simonmar Cleanup sweep and fix a bug in RTS flag processing.
simonmar authored
19 #include "RtsFlags.h"
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
20 #include "RtsUtils.h"
c56106f Use DLL aware runIO_closure instead of base_GHCziTopHandler_runIO_clo…
Ben.Lippmeier@anu.edu.au authored
21 #include "Prelude.h"
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
22 #include "Schedule.h" /* initScheduler */
23 #include "Stats.h" /* initStats */
b61f70c [project @ 2004-11-18 09:56:07 by tharris]
tharris authored
24 #include "STM.h" /* initSTM */
eba7b66 Merge the smp and threaded RTS ways
Simon Marlow authored
25 #include "RtsSignals.h"
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
26 #include "Weak.h"
ec48c5a [project @ 1999-01-21 10:31:41 by simonm]
simonm authored
27 #include "Ticky.h"
de89640 [project @ 2000-03-08 17:48:24 by simonmar]
simonmar authored
28 #include "StgRun.h"
51464cf [project @ 2000-03-14 14:34:47 by sewardj]
sewardj authored
29 #include "Prelude.h" /* fixupRTStoPreludeRefs */
fbbed91 [project @ 2002-06-26 08:18:38 by stolz]
stolz authored
30 #include "ThreadLabels.h"
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
31 #include "sm/BlockAlloc.h"
5a2769f New tracing interface
Simon Marlow authored
32 #include "Trace.h"
ab0e778 Split GC.c, and move storage manager into sm/ directory
Simon Marlow authored
33 #include "Stable.h"
62e61e0 @simonmar fix a warning
simonmar authored
34 #include "Hash.h"
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
35 #include "Profiling.h"
36 #include "Timer.h"
37 #include "Globals.h"
e020e38 FIX #2615 (linker scripts in .so files)
howard_b_golden@yahoo.com authored
38 void exitLinker( void ); // there is no Linker.h file to include
c850515 [project @ 2000-10-06 15:35:47 by simonmar]
simonmar authored
39
39a9917 [project @ 2000-11-01 11:41:47 by simonmar]
simonmar authored
40 #if defined(RTS_GTK_FRONTPANEL)
41 #include "FrontPanel.h"
42 #endif
43
cbeb99e Basic heap profile support without -prof
Simon Marlow authored
44 #if defined(PROFILING)
17315bf [project @ 1999-09-15 13:45:14 by simonmar]
simonmar authored
45 # include "ProfHeap.h"
db61851 [project @ 2001-11-22 14:25:11 by simonmar]
simonmar authored
46 # include "RetainerProfile.h"
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
47 #endif
48
de6c8e5 Remove the Windows Async IO Manager completely in THREADED_RTS mode
Simon Marlow authored
49 #if defined(mingw32_HOST_OS) && !defined(THREADED_RTS)
5b4f5a6 [project @ 2003-02-21 05:34:12 by sof]
sof authored
50 #include "win32/AsyncIO.h"
51 #endif
52
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
53 #if !defined(mingw32_HOST_OS)
54 #include "posix/TTY.h"
55 #include "posix/FileLock.h"
8fb92f9 [project @ 2003-09-24 10:32:11 by simonmar]
simonmar authored
56 #endif
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
57
addff19 @simonmar FIX part of #2301, and #1619
simonmar authored
58 #ifdef HAVE_UNISTD_H
59 #include <unistd.h>
60 #endif
1c83695 @simonmar Changes for the new IO library, mainly base-package modules moving ar…
simonmar authored
61 #ifdef HAVE_LOCALE_H
62 #include <locale.h>
63 #endif
8fb92f9 [project @ 2003-09-24 10:32:11 by simonmar]
simonmar authored
64
fe07f05 Addition of PAPI to RTS
mrchebas@gmail.com authored
65 #if USE_PAPI
66 #include "Papi.h"
67 #endif
68
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
69 // Count of how many outstanding hs_init()s there have been.
70 static int hs_init_count = 0;
674ad01 [project @ 2000-04-10 14:28:14 by sewardj]
sewardj authored
71
4bd153f [project @ 2004-09-12 12:12:18 by panne]
panne authored
72 /* -----------------------------------------------------------------------------
62db624 @simonmar comment updates
simonmar authored
73 Initialise floating point unit on x86 (currently disabled; See Note
74 [x86 Floating point precision] in compiler/nativeGen/X86/Instr.hs)
4bd153f [project @ 2004-09-12 12:12:18 by panne]
panne authored
75 -------------------------------------------------------------------------- */
76
77 #define X86_INIT_FPU 0
78
79 #if X86_INIT_FPU
80 static void
81 x86_init_fpu ( void )
82 {
83 __volatile unsigned short int fpu_cw;
84
85 // Grab the control word
86 __asm __volatile ("fnstcw %0" : "=m" (fpu_cw));
87
88 #if 0
89 printf("fpu_cw: %x\n", fpu_cw);
90 #endif
91
92 // Set bits 8-9 to 10 (64-bit precision).
93 fpu_cw = (fpu_cw & 0xfcff) | 0x0200;
94
95 // Store the new control word back
96 __asm __volatile ("fldcw %0" : : "m" (fpu_cw));
97 }
423d477 [project @ 2004-08-13 13:04:50 by simonmar]
simonmar authored
98 #endif
99
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
100 /* -----------------------------------------------------------------------------
101 Starting up the RTS
102 -------------------------------------------------------------------------- */
674ad01 [project @ 2000-04-10 14:28:14 by sewardj]
sewardj authored
103
104 void
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
105 hs_init(int *argc, char **argv[])
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
106 {
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
107 hs_init_count++;
108 if (hs_init_count > 1) {
109 // second and subsequent inits are ignored
110 return;
b240523 [project @ 2001-12-06 07:07:12 by sof]
sof authored
111 }
5c089c2 [project @ 1999-03-03 19:10:37 by sof]
sof authored
112
1c83695 @simonmar Changes for the new IO library, mainly base-package modules moving ar…
simonmar authored
113 setlocale(LC_CTYPE,"");
114
1663532 calculate and report slop (wasted space at the end of blocks)
Simon Marlow authored
115 /* Initialise the stats department, phase 0 */
116 initStats0();
d526504 @igfoo When debugging, have the allocator help us a bit
igfoo authored
117
118 /* Next we do is grab the start time...just in case we're
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
119 * collecting timing statistics.
120 */
57c9c08 [project @ 2000-12-19 14:30:58 by simonmar]
simonmar authored
121 stat_startInit();
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
122
123 /* Set the RTS flags to default values. */
fe07f05 Addition of PAPI to RTS
mrchebas@gmail.com authored
124
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
125 initRtsFlagsDefaults();
126
127 /* Call the user hook to reset defaults, if present */
128 defaultsHook();
129
130 /* Parse the flags, separating the RTS flags from the programs args */
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
131 if (argc != NULL && argv != NULL) {
8bac478 @igfoo Implement the RTS side of GHC.Environment.getFullArgs
igfoo authored
132 setFullProgArgv(*argc,*argv);
5463b55 @simonmar Cleanup sweep and fix a bug in RTS flag processing.
simonmar authored
133 setupRtsFlags(argc, *argv);
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
134 }
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
135
1663532 calculate and report slop (wasted space at the end of blocks)
Simon Marlow authored
136 /* Initialise the stats department, phase 1 */
137 initStats1();
138
8db56c8 improvements to PAPI support
simonmar@microsoft.com authored
139 #ifdef USE_PAPI
140 papi_init();
141 #endif
142
5a2769f New tracing interface
Simon Marlow authored
143 /* initTracing must be after setupRtsFlags() */
a5288c5 @simonmar Unify event logging and debug tracing.
simonmar authored
144 #ifdef TRACING
5a2769f New tracing interface
Simon Marlow authored
145 initTracing();
8b18fae @simonmar Add fast event logging
simonmar authored
146 #endif
c4f9b98 @dcoutts Make the tracing of the startup event more regular
dcoutts authored
147 /* Trace the startup event
015d3d4 @mchakravarty Expose all EventLog events as DTrace probes
mchakravarty authored
148 */
c4f9b98 @dcoutts Make the tracing of the startup event more regular
dcoutts authored
149 traceEventStartup();
5a2769f New tracing interface
Simon Marlow authored
150
f669261 [project @ 1999-11-02 15:05:38 by simonmar]
simonmar authored
151 /* initialise scheduler data structures (needs to be done before
152 * initStorage()).
153 */
154 initScheduler();
155
e8832eb @dcoutts Emit various bits of OS process info into the eventlog
dcoutts authored
156 /* Trace some basic information about the process */
157 traceOSProcessInfo();
158
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
159 /* initialize the storage manager */
160 initStorage();
161
162 /* initialise the stable pointer table */
163 initStablePtrTable();
164
cb73be0 @simonmar add some more GC roots (fixes conc048, and possibly some others)
simonmar authored
165 /* Add some GC roots for things in the base package that the RTS
166 * knows about. We don't know whether these turn out to be CAFs
167 * or refer to CAFs, but we have to assume that they might.
4e1f119 @simonmar FIX #2554: GHC.TopHandler.{runIO,runNonIO} should be GC roots
simonmar authored
168 */
c56106f Use DLL aware runIO_closure instead of base_GHCziTopHandler_runIO_clo…
Ben.Lippmeier@anu.edu.au authored
169 getStablePtr((StgPtr)runIO_closure);
170 getStablePtr((StgPtr)runNonIO_closure);
849ce0c @simonmar Add some missing getStablePtr()s for CAFs that the RTS refers to
simonmar authored
171
172 getStablePtr((StgPtr)runFinalizerBatch_closure);
173
cb73be0 @simonmar add some more GC roots (fixes conc048, and possibly some others)
simonmar authored
174 getStablePtr((StgPtr)stackOverflow_closure);
175 getStablePtr((StgPtr)heapOverflow_closure);
176 getStablePtr((StgPtr)unpackCString_closure);
a916885 @simonmar Handle renames from #3310
simonmar authored
177 getStablePtr((StgPtr)blockedIndefinitelyOnMVar_closure);
cb73be0 @simonmar add some more GC roots (fixes conc048, and possibly some others)
simonmar authored
178 getStablePtr((StgPtr)nonTermination_closure);
a916885 @simonmar Handle renames from #3310
simonmar authored
179 getStablePtr((StgPtr)blockedIndefinitelyOnSTM_closure);
849ce0c @simonmar Add some missing getStablePtr()s for CAFs that the RTS refers to
simonmar authored
180 getStablePtr((StgPtr)nestedAtomically_closure);
181
182 getStablePtr((StgPtr)runSparks_closure);
183 getStablePtr((StgPtr)ensureIOManagerIsRunning_closure);
243c043 @simonmar fix Windows build (GHC.Conc.runHandlers is Unix-only)
simonmar authored
184 #ifndef mingw32_HOST_OS
849ce0c @simonmar Add some missing getStablePtr()s for CAFs that the RTS refers to
simonmar authored
185 getStablePtr((StgPtr)runHandlers_closure);
243c043 @simonmar fix Windows build (GHC.Conc.runHandlers is Unix-only)
simonmar authored
186 #endif
4e1f119 @simonmar FIX #2554: GHC.TopHandler.{runIO,runNonIO} should be GC roots
simonmar authored
187
52589e0 Add shared Typeable support
Esa Ilari Vuokko authored
188 /* initialise the shared Typeable store */
2b569f5 @simonmar add getOrSetSignalHandlerStore, much like getOrSetTypeableStore
simonmar authored
189 initGlobalStore();
52589e0 Add shared Typeable support
Esa Ilari Vuokko authored
190
1d02661 Move file locking into the RTS, fixing #629, #1109
Simon Marlow authored
191 /* initialise file locking, if necessary */
192 #if !defined(mingw32_HOST_OS)
193 initFileLocking();
194 #endif
195
f7db2c3 [project @ 2004-09-22 16:37:23 by sof]
sof authored
196 #if defined(DEBUG)
fbbed91 [project @ 2002-06-26 08:18:38 by stolz]
stolz authored
197 /* initialise thread label table (tso->char*) */
198 initThreadLabelTable();
f7db2c3 [project @ 2004-09-22 16:37:23 by sof]
sof authored
199 #endif
fbbed91 [project @ 2002-06-26 08:18:38 by stolz]
stolz authored
200
de89640 [project @ 2000-03-08 17:48:24 by simonmar]
simonmar authored
201 initProfiling1();
202
e30e0fb [project @ 2001-11-27 01:51:23 by sof]
sof authored
203 /* start the virtual timer 'subsystem'. */
8d71be7 FIX #1623: disable the timer signal when the system is idle (threaded…
Simon Marlow authored
204 initTimer();
93db199 @igfoo new RTS flag: -V to modify the resolution of the RTS timer
igfoo authored
205 startTimer();
c6ab4bf [project @ 1999-08-25 16:11:43 by simonmar]
simonmar authored
206
c49a6ca [project @ 2003-04-01 15:05:13 by sof]
sof authored
207 #if defined(RTS_USER_SIGNALS)
4cc37e5 @igfoo Add an --install-signal-handlers=<yes|no> RTS flag; fixes trac #804
igfoo authored
208 if (RtsFlags.MiscFlags.install_signal_handlers) {
209 /* Initialise the user signal handler set */
210 initUserSignals();
211 /* Set up handler to run on SIGINT, etc. */
212 initDefaultHandlers();
213 }
e1dffdb [project @ 1999-09-13 11:02:08 by sof]
sof authored
214 #endif
5c089c2 [project @ 1999-03-03 19:10:37 by sof]
sof authored
215
de6c8e5 Remove the Windows Async IO Manager completely in THREADED_RTS mode
Simon Marlow authored
216 #if defined(mingw32_HOST_OS) && !defined(THREADED_RTS)
5b4f5a6 [project @ 2003-02-21 05:34:12 by sof]
sof authored
217 startupAsyncIO();
218 #endif
219
39a9917 [project @ 2000-11-01 11:41:47 by simonmar]
simonmar authored
220 #ifdef RTS_GTK_FRONTPANEL
221 if (RtsFlags.GcFlags.frontpanel) {
222 initFrontPanel();
223 }
224 #endif
225
4bd153f [project @ 2004-09-12 12:12:18 by panne]
panne authored
226 #if X86_INIT_FPU
227 x86_init_fpu();
423d477 [project @ 2004-08-13 13:04:50 by simonmar]
simonmar authored
228 #endif
229
a52ff76 @simonmar Change the way module initialisation is done (#3252, #4417)
simonmar authored
230 startupHpc();
231
232 // This must be done after module initialisation.
233 // ToDo: make this work in the presence of multiple hs_add_root()s.
234 initProfiling2();
235
236 // ditto.
237 #if defined(THREADED_RTS)
238 ioManagerStart();
239 #endif
240
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
241 /* Record initialization times */
57c9c08 [project @ 2000-12-19 14:30:58 by simonmar]
simonmar authored
242 stat_endInit();
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
243 }
244
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
245 // Compatibility interface
246 void
a52ff76 @simonmar Change the way module initialisation is done (#3252, #4417)
simonmar authored
247 startupHaskell(int argc, char *argv[], void (*init_root)(void) STG_UNUSED)
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
248 {
249 hs_init(&argc, &argv);
250 }
251
252
253 /* -----------------------------------------------------------------------------
a52ff76 @simonmar Change the way module initialisation is done (#3252, #4417)
simonmar authored
254 hs_add_root: backwards compatibility. (see #3252)
de89640 [project @ 2000-03-08 17:48:24 by simonmar]
simonmar authored
255 -------------------------------------------------------------------------- */
256
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
257 void
a52ff76 @simonmar Change the way module initialisation is done (#3252, #4417)
simonmar authored
258 hs_add_root(void (*init_root)(void) STG_UNUSED)
de89640 [project @ 2000-03-08 17:48:24 by simonmar]
simonmar authored
259 {
a52ff76 @simonmar Change the way module initialisation is done (#3252, #4417)
simonmar authored
260 /* nothing */
de89640 [project @ 2000-03-08 17:48:24 by simonmar]
simonmar authored
261 }
dac8c9b [project @ 2000-03-09 11:49:34 by simonmar]
simonmar authored
262
681aad9 hs_exit()/shutdownHaskell(): wait for outstanding foreign calls to co…
Simon Marlow authored
263 /* ----------------------------------------------------------------------------
264 * Shutting down the RTS
265 *
266 * The wait_foreign parameter means:
267 * True ==> wait for any threads doing foreign calls now.
268 * False ==> threads doing foreign calls may return in the
269 * future, but will immediately block on a mutex.
270 * (capability->lock).
271 *
272 * If this RTS is a DLL that we're about to unload, then you want
273 * safe=True, otherwise the thread might return to code that has been
274 * unloaded. If this is a standalone program that is about to exit,
275 * then you can get away with safe=False, which is better because we
276 * won't hang on exit if there is a blocked foreign call outstanding.
277 *
278 ------------------------------------------------------------------------- */
d1a47b3 [project @ 1999-07-03 18:39:40 by sof]
sof authored
279
681aad9 hs_exit()/shutdownHaskell(): wait for outstanding foreign calls to co…
Simon Marlow authored
280 static void
281 hs_exit_(rtsBool wait_foreign)
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
282 {
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
283 if (hs_init_count <= 0) {
4ae1107 Turn the "too many hs_exit()s" fatal error into a warning
Simon Marlow authored
284 errorBelch("warning: too many hs_exit()s");
285 return;
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
286 }
287 hs_init_count--;
288 if (hs_init_count > 0) {
289 // ignore until it's the last one
290 return;
291 }
32a2762 [project @ 2002-05-11 00:16:11 by sof]
sof authored
292
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
293 /* start timing the shutdown */
294 stat_startExit();
295
addff19 @simonmar FIX part of #2301, and #1619
simonmar authored
296 OnExitHook();
297
035b8eb @simonmar Add a debug check for a non-empty FPU stack on x86 (see #4914)
simonmar authored
298 // sanity check
299 #if defined(DEBUG)
300 checkFPUStack();
301 #endif
302
80a766f Add support for the IO manager thread on Windows
Simon Marlow authored
303 #if defined(THREADED_RTS)
7a1f8fb Better control of the IO manager thread; improvements to deadlock che…
Simon Marlow authored
304 ioManagerDie();
305 #endif
306
8fcae51 [project @ 2004-02-27 13:35:16 by simonmar]
simonmar authored
307 /* stop all running tasks */
681aad9 hs_exit()/shutdownHaskell(): wait for outstanding foreign calls to co…
Simon Marlow authored
308 exitScheduler(wait_foreign);
6c095bf @simonmar FIX #1364: added support for C finalizers that run as soon as the val…
simonmar authored
309
310 /* run C finalizers for all active weak pointers */
311 runAllCFinalizers(weak_ptr_list);
8fcae51 [project @ 2004-02-27 13:35:16 by simonmar]
simonmar authored
312
7ed3f75 @simonmar Rewrite of signal-handling (ghc patch; see also base and unix patches)
simonmar authored
313 #if defined(RTS_USER_SIGNALS)
314 if (RtsFlags.MiscFlags.install_signal_handlers) {
315 freeSignalHandlers();
316 }
317 #endif
318
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
319 /* stop the ticker */
557947d [project @ 2003-02-22 04:51:50 by sof]
sof authored
320 stopTimer();
bb7b45d @simonmar Don't Terminate the ticker thread (#3748)
simonmar authored
321 exitTimer(wait_foreign);
5ddee76 @catamorphism Lightweight ticky-ticky profiling
catamorphism authored
322
a2a67cd @simonmar RTS tidyup sweep, first phase
simonmar authored
323 // set the terminal settings back to what they were
324 #if !defined(mingw32_HOST_OS)
325 resetTerminalSettings();
8fb92f9 [project @ 2003-09-24 10:32:11 by simonmar]
simonmar authored
326 #endif
327
addff19 @simonmar FIX part of #2301, and #1619
simonmar authored
328 // uninstall signal handlers
329 resetDefaultHandlers();
330
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
331 /* stop timing the shutdown, we're about to print stats */
332 stat_endExit();
333
d5934bb Haskell Program Coverage
andy@galois.com authored
334 /* shutdown the hpc support (if needed) */
335 exitHpc();
336
71d6db2 fix profiling on Win32
Simon Marlow authored
337 // clean up things from the storage manager's point of view.
338 // also outputs the stats (+RTS -s) info.
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
339 exitStorage();
340
cf6b495 @igfoo Add freeScheduler/freeTaskManager and call it later than exitScheduler
igfoo authored
341 /* free the tasks */
342 freeScheduler();
343
52589e0 Add shared Typeable support
Esa Ilari Vuokko authored
344 /* free shared Typeable store */
2b569f5 @simonmar add getOrSetSignalHandlerStore, much like getOrSetTypeableStore
simonmar authored
345 exitGlobalStore();
52589e0 Add shared Typeable support
Esa Ilari Vuokko authored
346
e020e38 FIX #2615 (linker scripts in .so files)
howard_b_golden@yahoo.com authored
347 /* free linker data */
348 exitLinker();
349
1d02661 Move file locking into the RTS, fixing #629, #1109
Simon Marlow authored
350 /* free file locking tables, if necessary */
351 #if !defined(mingw32_HOST_OS)
352 freeFileLocking();
353 #endif
354
221e74f @igfoo Free various things we allocate
igfoo authored
355 /* free the stable pointer table */
9f2ceb4 Remember to free() memory on exit
Simon Marlow authored
356 exitStablePtrTable();
357
221e74f @igfoo Free various things we allocate
igfoo authored
358 #if defined(DEBUG)
359 /* free the thread label table */
360 freeThreadLabelTable();
361 #endif
362
39a9917 [project @ 2000-11-01 11:41:47 by simonmar]
simonmar authored
363 #ifdef RTS_GTK_FRONTPANEL
364 if (RtsFlags.GcFlags.frontpanel) {
365 stopFrontPanel();
366 }
367 #endif
368
db61851 [project @ 2001-11-22 14:25:11 by simonmar]
simonmar authored
369 #if defined(PROFILING)
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
370 reportCCSProfiling();
db61851 [project @ 2001-11-22 14:25:11 by simonmar]
simonmar authored
371 #endif
372
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
373 endProfiling();
a52ff76 @simonmar Change the way module initialisation is done (#3252, #4417)
simonmar authored
374 freeProfiling();
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
375
db61851 [project @ 2001-11-22 14:25:11 by simonmar]
simonmar authored
376 #ifdef PROFILING
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
377 // Originally, this was in report_ccs_profiling(). Now, retainer
378 // profiling might tack some extra stuff on to the end of this file
379 // during endProfiling().
9ac03f0 @simonmar FIX #2234: don't generate <prog>.prof unless we're going to put somet…
simonmar authored
380 if (prof_file != NULL) fclose(prof_file);
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
381 #endif
71d6db2 fix profiling on Win32
Simon Marlow authored
382
a5288c5 @simonmar Unify event logging and debug tracing.
simonmar authored
383 #ifdef TRACING
384 endTracing();
385 freeTracing();
8b18fae @simonmar Add fast event logging
simonmar authored
386 #endif
387
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
388 #if defined(TICKY_TICKY)
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
389 if (RtsFlags.TickyFlags.showTickyStats) PrintTickyInfo();
390 #endif
5b4f5a6 [project @ 2003-02-21 05:34:12 by sof]
sof authored
391
de6c8e5 Remove the Windows Async IO Manager completely in THREADED_RTS mode
Simon Marlow authored
392 #if defined(mingw32_HOST_OS) && !defined(THREADED_RTS)
eb5791f FIX #1177, partially at least.
Simon Marlow authored
393 shutdownAsyncIO(wait_foreign);
5b4f5a6 [project @ 2003-02-21 05:34:12 by sof]
sof authored
394 #endif
71d6db2 fix profiling on Win32
Simon Marlow authored
395
897bcbf FIX: #1227 (biographical profiling broken)
Simon Marlow authored
396 /* free hash table storage */
397 exitHashTable();
398
ae03da7 @simonmar during shutdown, only free the heap if we waited for foreign calls to…
simonmar authored
399 // Finally, free all our storage. However, we only free the heap
400 // memory if we have waited for foreign calls to complete;
401 // otherwise a foreign call in progress may still be referencing
402 // heap memory (e.g. by being passed a ByteArray#).
403 freeStorage(wait_foreign);
d526504 @igfoo When debugging, have the allocator help us a bit
igfoo authored
404
a6e8418 @simonmar prog_argv and rts_argv now contain *copies* of the args passed to
simonmar authored
405 // Free the various argvs
406 freeRtsArgs();
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
407 }
408
681aad9 hs_exit()/shutdownHaskell(): wait for outstanding foreign calls to co…
Simon Marlow authored
409 // The real hs_exit():
410 void
411 hs_exit(void)
412 {
413 hs_exit_(rtsTrue);
414 // be safe; this might be a DLL
415 }
416
34b568c [project @ 2003-01-28 16:30:06 by simonmar]
simonmar authored
417 // Compatibility interfaces
418 void
419 shutdownHaskell(void)
420 {
421 hs_exit();
422 }
423
424 void
425 shutdownHaskellAndExit(int n)
426 {
d18b5d5 @simonmar make shutdownHaskellAndExit() shut down the RTS and exit immediately
simonmar authored
427 // even if hs_init_count > 1, we still want to shut down the RTS
428 // and exit immediately (see #5402)
429 hs_init_count = 1;
430
addff19 @simonmar FIX part of #2301, and #1619
simonmar authored
431 // we're about to exit(), no need to wait for foreign calls to return.
432 hs_exit_(rtsFalse);
433
d18b5d5 @simonmar make shutdownHaskellAndExit() shut down the RTS and exit immediately
simonmar authored
434 stg_exit(n);
1b28d4e [project @ 2000-01-13 14:33:57 by hwloidl]
hwloidl authored
435 }
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
436
addff19 @simonmar FIX part of #2301, and #1619
simonmar authored
437 #ifndef mingw32_HOST_OS
438 void
439 shutdownHaskellAndSignal(int sig)
440 {
441 hs_exit_(rtsFalse);
442 kill(getpid(),sig);
443 }
444 #endif
445
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
446 /*
9903274 [project @ 1999-07-06 15:33:23 by simonmar]
simonmar authored
447 * called from STG-land to exit the program
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
448 */
449
7b1b327 make exit() overridable, for use in DLLs
Simon Marlow authored
450 void (*exitFn)(int) = 0;
451
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
452 void
0bffc41 [project @ 2002-12-11 15:36:20 by simonmar]
simonmar authored
453 stg_exit(int n)
20fc2f0 [project @ 2001-03-22 03:51:08 by hwloidl]
hwloidl authored
454 {
7b1b327 make exit() overridable, for use in DLLs
Simon Marlow authored
455 if (exitFn)
456 (*exitFn)(n);
20fc2f0 [project @ 2001-03-22 03:51:08 by hwloidl]
hwloidl authored
457 exit(n);
4385968 [project @ 1998-12-02 13:17:09 by simonm]
simonm authored
458 }
Something went wrong with that request. Please try again.