-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coroutines: get photonlib/coroutines working with GC
- Loading branch information
1 parent
1f06476
commit 9604a3f
Showing
3 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,28 @@ fn C.photon_init_default() int | |
fn C.photon_thread_create(f voidptr, arg voidptr) | ||
fn C.photon_sleep_s(n int) | ||
fn C.photon_sleep_ms(n int) | ||
fn C.set_photon_thread_stack_allocator(fn (voidptr, int) voidptr, fn (voidptr, voidptr, int)) | ||
|
||
// sleep is coroutine-safe version of time.sleep() | ||
pub fn sleep(duration time.Duration) { | ||
C.photon_sleep_ms(duration.milliseconds()) | ||
} | ||
|
||
fn init() { | ||
alloc := fn (_ voidptr, stack_size int) voidptr { | ||
unsafe { | ||
stack_ptr := malloc(stack_size) | ||
C.GC_add_roots(stack_ptr, charptr(stack_ptr) + stack_size) | ||
return stack_ptr | ||
} | ||
} | ||
dealloc := fn (_ voidptr, stack_ptr voidptr, stack_size int) { | ||
unsafe { | ||
C.GC_add_roots(stack_ptr, charptr(stack_ptr) + stack_size) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joe-conigliaro
Author
Member
|
||
free(stack_ptr) | ||
} | ||
} | ||
C.set_photon_thread_stack_allocator(alloc, dealloc) | ||
ret := C.photon_init_default() | ||
if ret < 0 { | ||
panic('failed to initialize coroutines via photon (ret=${ret})') | ||
|
should it be something like GC_remove_root?