diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fac5010..36cca4e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add `janet_thread_current(void)` to C API - Add integer parsing forms to pegs. This makes parsing many binary protocols easier. - Lots of updates to networking code - now can use epoll (or poll) on linux and IOCP on windows. - Add `ev/` module. This exposes a fiber scheduler, queues, timeouts, and other functionality to users diff --git a/src/core/thread.c b/src/core/thread.c index 7a19c707..9c798f56 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -585,6 +585,14 @@ void janet_threads_deinit(void) { janet_vm_thread_decode = NULL; } +JanetThread *janet_thread_current(void) { + if (NULL == janet_vm_thread_current) { + janet_vm_thread_current = janet_make_thread(janet_vm_mailbox, janet_get_core_table("make-image-dict")); + janet_gcroot(janet_wrap_abstract(janet_vm_thread_current)); + } + return janet_vm_thread_current; +} + /* * Cfuns */ @@ -592,11 +600,7 @@ void janet_threads_deinit(void) { static Janet cfun_thread_current(int32_t argc, Janet *argv) { (void) argv; janet_fixarity(argc, 0); - if (NULL == janet_vm_thread_current) { - janet_vm_thread_current = janet_make_thread(janet_vm_mailbox, janet_get_core_table("make-image-dict")); - janet_gcroot(janet_wrap_abstract(janet_vm_thread_current)); - } - return janet_wrap_abstract(janet_vm_thread_current); + return janet_wrap_abstract(janet_thread_current()); } static Janet cfun_thread_new(int32_t argc, Janet *argv) {