diff options
| author | Aiden Gall <aiden@aidengall.xyz> | 2025-02-11 12:45:45 +0000 |
|---|---|---|
| committer | Aiden Gall <aiden@aidengall.xyz> | 2025-02-11 12:45:45 +0000 |
| commit | 0ed31de7833d16e03846ad00f127d2c7f4c8f2a6 (patch) | |
| tree | d8531f0a06b0469f05055d9b5751d1a11ee2e951 /tco_go.3 | |
| parent | 51852ce6d2f87cfb45e3efd5f2bc474d86c7ff8d (diff) | |
(tco_args) add support for coroutine arguments
Diffstat (limited to 'tco_go.3')
| -rw-r--r-- | tco_go.3 | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -1,6 +1,6 @@ .TH tco_go 3 2025-02-06 .SH NAME -tco_go, tco_yield +tco_go, tco_args, tco_yield .SH LIBRARY Tiny Coroutines .RI ( libtco ", " \-ltco ) @@ -8,7 +8,8 @@ Tiny Coroutines .nf .B #include <tco.h> .P -.BI "int tco_go(void (*f)(void));" +.BI "int tco_go(void (*" f ")(...));" +.B "int tco_args(...);" .BI "void tco_yield(void);" .fi .SH DESCRIPTION @@ -19,17 +20,19 @@ The coroutine function pointer .I f is required to not be inlined (the -.BR coroutine +.B coroutine macro is provided as a convienient way to use the -.BR gcc (1) -/ -.BR clang (1) -.BR noinline +.BR gcc (1)/ clang (1) +.B noinline attribute, and to communicate the intented use of a function as a coroutine). When the scheduler switches back to a context that has called .BR tco_go (), it resumes execution from after that call. .P +.BR tco_args () +sets the function arguments given to the coroutine spawned by +.BR tco_go (). +.P .BR tco_yield () saves the current execution context and switches to the next scheduled context, pausing execution of the current coroutine. @@ -43,8 +46,23 @@ returns 0 on success, and a non-zero error code when the coroutine fails to initialise. .SH CAVEATS This library works by preserving the state of the callee-saved registers and -restoring them later when the coroutine is resumed. This approach may be -incompatible with other forms of black magic voodoo, your mileage may vary. +restoring them later when the coroutine is resumed. +This approach may be incompatible with other forms of black magic voodoo, your +mileage may vary. +.P +.BR tco_args () +currently only supports arguments passed by registers +.RI ( %rdi , +.IR %rsi , +.IR %rdx , +.IR %r10 , +.IR %r8 , +.I %r9 +and +.IR %xmm0\-8 ). +Spawning coroutines that take arguments on the stack will result in stack +corruption. +Refer to the System V ABI for more details. .SH AUTHOR AND LICENSE Copyright (C) 2025 Aiden Gall .P |
