Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / runtime / gc / enter_leave.c
CommitLineData
7f918cf1
CE
1/* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 */
8
9/* enter and leave should be called at the start and end of every GC
10 * function that is exported to the outside world. They make sure
11 * that the function is run in a critical section and check the GC
12 * invariant.
13 */
14void enter (GC_state s) {
15 if (DEBUG)
16 fprintf (stderr, "enter\n");
17 /* used needs to be set because the mutator has changed s->stackTop. */
18 getStackCurrent(s)->used = sizeofGCStateCurrentStackUsed (s);
19 getThreadCurrent(s)->exnStack = s->exnStack;
20 if (DEBUG)
21 displayGCState (s, stderr);
22 beginAtomic (s);
23 assert (invariantForGC (s));
24 if (DEBUG)
25 fprintf (stderr, "enter ok\n");
26}
27
28void leave (GC_state s) {
29 if (DEBUG)
30 fprintf (stderr, "leave\n");
31 /* The mutator frontier invariant may not hold
32 * for functions that don't ensureBytesFree.
33 */
34 assert (invariantForMutator (s, FALSE, TRUE));
35 endAtomic (s);
36 if (DEBUG)
37 fprintf (stderr, "leave ok\n");
38}