.TH tco_go 3 2025-02-06 .SH NAME tco_go, tco_yield .SH LIBRARY Tiny Coroutines .RI ( libtco ", " \-ltco ) .SH SYNOPSIS .nf .B #include .P .BI "int tco_go(void (*f)(void));" .BI "void tco_yield(void);" .fi .SH DESCRIPTION .BR tco_go () spawns a coroutine context with its own stack, then saves the current execution context and switches to the new coroutine. The coroutine function pointer .I f is required to not be inlined (the .BR coroutine macro is provided as a convienient way to use the .BR gcc (1) / .BR clang (1) .BR 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_yield () saves the current execution context and switches to the next scheduled context, pausing execution of the current coroutine. Tasks are scheduled in a round-robin fashion. .P Functions scheduled as coroutines are automatically deinitialised when they return. .SH RETURN VALUE .BR tco_go () 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. .SH AUTHOR AND LICENSE Copyright (C) 2025 Aiden Gall .P This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. .P This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. .P You should have received a copy of the GNU General Public License along with this program. If not, see .