1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * Development of the code in this file was sponsored by Microbric Pty Ltd
5  *
6  * The MIT License (MIT)
7  *
8  * Copyright (c) 2014 Damien P. George
9  * Copyright (c) 2017 Pycom Limited
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  */
29 
30 #include <stdio.h>
31 
32 #include "py/mpconfig.h"
33 #include "py/mpstate.h"
34 #include "py/gc.h"
35 #include "py/mpthread.h"
36 #include "gccollect.h"
37 
gc_collect_inner(int level)38 static void gc_collect_inner(int level) {
39     // trace root pointers from any threads
40     #if MICROPY_PY_THREAD
41     mp_thread_gc_others();
42     #endif
43 }
44 
gc_collect(void)45 void gc_collect(void) {
46     gc_collect_start();
47 
48     // trace the stack and registers
49     gc_helper_collect_regs_and_stack();
50 
51     gc_collect_inner(0);
52     gc_collect_end();
53 }
54