Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
Damien George | 51dfcb4 | 2015-01-01 20:27:54 +0000 | [diff] [blame] | 26 | #ifndef __MICROPY_INCLUDED_PY_GC_H__ |
| 27 | #define __MICROPY_INCLUDED_PY_GC_H__ |
| 28 | |
| 29 | #include <stdint.h> |
| 30 | |
| 31 | #include "py/mpconfig.h" |
| 32 | #include "py/misc.h" |
Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 33 | |
Damien | dcced92 | 2013-10-21 23:45:08 +0100 | [diff] [blame] | 34 | void gc_init(void *start, void *end); |
Damien George | 443e018 | 2014-04-08 11:31:21 +0000 | [diff] [blame] | 35 | |
| 36 | // These lock/unlock functions can be nested. |
| 37 | // They can be used to prevent the GC from allocating/freeing. |
| 38 | void gc_lock(void); |
| 39 | void gc_unlock(void); |
Dave Hylands | 2fe841d | 2014-06-30 22:49:21 -0700 | [diff] [blame] | 40 | bool gc_is_locked(void); |
Damien George | 443e018 | 2014-04-08 11:31:21 +0000 | [diff] [blame] | 41 | |
| 42 | // A given port must implement gc_collect by using the other collect functions. |
| 43 | void gc_collect(void); |
Damien | 8b3a7c2 | 2013-10-23 20:20:17 +0100 | [diff] [blame] | 44 | void gc_collect_start(void); |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 45 | void gc_collect_root(void **ptrs, mp_uint_t len); |
Damien | 8b3a7c2 | 2013-10-23 20:20:17 +0100 | [diff] [blame] | 46 | void gc_collect_end(void); |
Damien George | 443e018 | 2014-04-08 11:31:21 +0000 | [diff] [blame] | 47 | |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 48 | void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser); |
Damien | fd8b6bc | 2013-10-22 20:26:36 +0100 | [diff] [blame] | 49 | void gc_free(void *ptr); |
Damien George | 0b13f3e | 2014-10-24 23:12:25 +0100 | [diff] [blame] | 50 | mp_uint_t gc_nbytes(const void *ptr); |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 51 | void *gc_realloc(void *ptr, mp_uint_t n_bytes); |
Damien | eefcc79 | 2013-10-22 15:25:25 +0100 | [diff] [blame] | 52 | |
| 53 | typedef struct _gc_info_t { |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 54 | mp_uint_t total; |
| 55 | mp_uint_t used; |
| 56 | mp_uint_t free; |
| 57 | mp_uint_t num_1block; |
| 58 | mp_uint_t num_2block; |
| 59 | mp_uint_t max_block; |
Damien | eefcc79 | 2013-10-22 15:25:25 +0100 | [diff] [blame] | 60 | } gc_info_t; |
| 61 | |
| 62 | void gc_info(gc_info_t *info); |
Paul Sokolovsky | 550d804 | 2014-02-11 23:53:34 +0200 | [diff] [blame] | 63 | void gc_dump_info(void); |
Damien George | ce1162a | 2014-02-26 22:55:59 +0000 | [diff] [blame] | 64 | void gc_dump_alloc_table(void); |
Damien George | 51dfcb4 | 2015-01-01 20:27:54 +0000 | [diff] [blame] | 65 | |
| 66 | #endif // __MICROPY_INCLUDED_PY_GC_H__ |