diff options
author | Damien George <damien.p.george@gmail.com> | 2016-05-04 10:23:21 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-06-28 11:28:49 +0100 |
commit | dbd54e0b5bf50c42127b8f55a873e466cef2e0b7 (patch) | |
tree | 473f43d1ebf55b3eed80f93f8d59079ebe4dc73a /unix/gccollect.c | |
parent | 9172c0cb252faa47f56e61f67ceb213012631de2 (diff) |
unix: Implement garbage collection with threading.
This patch allows any given thread to do a proper garbage collection and
scan all the pointers of all active threads.
Diffstat (limited to 'unix/gccollect.c')
-rw-r--r-- | unix/gccollect.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/unix/gccollect.c b/unix/gccollect.c index 7e8fe456a..3e012b542 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -136,15 +136,22 @@ STATIC void gc_helper_get_regs(regs_t arr) { #endif // MICROPY_GCREGS_SETJMP -void gc_collect(void) { - //gc_dump_info(); - - gc_collect_start(); +void gc_collect_regs_and_stack(void) { regs_t regs; gc_helper_get_regs(regs); // GC stack (and regs because we captured them) void **regs_ptr = (void**)(void*)®s; gc_collect_root(regs_ptr, ((uintptr_t)MP_STATE_THREAD(stack_top) - (uintptr_t)®s) / sizeof(uintptr_t)); +} + +void gc_collect(void) { + //gc_dump_info(); + + gc_collect_start(); + gc_collect_regs_and_stack(); + #if MICROPY_PY_THREAD + mp_thread_gc_others(); + #endif #if MICROPY_EMIT_NATIVE mp_unix_mark_exec(); #endif |