blob: fd48d26645e679f17b58a381d92d0c18997c7a2d [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
Damiendcced922013-10-21 23:45:08 +010027void gc_init(void *start, void *end);
Damien George443e0182014-04-08 11:31:21 +000028
29// These lock/unlock functions can be nested.
30// They can be used to prevent the GC from allocating/freeing.
31void gc_lock(void);
32void gc_unlock(void);
Dave Hylands2fe841d2014-06-30 22:49:21 -070033bool gc_is_locked(void);
Damien George443e0182014-04-08 11:31:21 +000034
35// A given port must implement gc_collect by using the other collect functions.
36void gc_collect(void);
Damien8b3a7c22013-10-23 20:20:17 +010037void gc_collect_start(void);
Damien George40f3c022014-07-03 13:25:24 +010038void gc_collect_root(void **ptrs, mp_uint_t len);
Damien8b3a7c22013-10-23 20:20:17 +010039void gc_collect_end(void);
Damien George443e0182014-04-08 11:31:21 +000040
Damien George40f3c022014-07-03 13:25:24 +010041void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser);
Damienfd8b6bc2013-10-22 20:26:36 +010042void gc_free(void *ptr);
Damien George40f3c022014-07-03 13:25:24 +010043mp_uint_t gc_nbytes(void *ptr);
44void *gc_realloc(void *ptr, mp_uint_t n_bytes);
Damieneefcc792013-10-22 15:25:25 +010045
46typedef struct _gc_info_t {
Damien George40f3c022014-07-03 13:25:24 +010047 mp_uint_t total;
48 mp_uint_t used;
49 mp_uint_t free;
50 mp_uint_t num_1block;
51 mp_uint_t num_2block;
52 mp_uint_t max_block;
Damieneefcc792013-10-22 15:25:25 +010053} gc_info_t;
54
55void gc_info(gc_info_t *info);
Paul Sokolovsky550d8042014-02-11 23:53:34 +020056void gc_dump_info(void);
Damien Georgece1162a2014-02-26 22:55:59 +000057void gc_dump_alloc_table(void);