mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Implement swapcontext() and makecontext()
This change introduces support for Linux-style uc_context manipulation that's fast and works well on all supported OSes and architectures. It also integrates with the Cosmpolitan runtime which can show backtraces comprised of multiple stacks and fibers. See the test and example code for further details. This will be used by Mold once it's been vendored
This commit is contained in:
parent
7ec84655b4
commit
197aa0d465
28 changed files with 617 additions and 355 deletions
|
@ -83,3 +83,19 @@ void SetGetContext(void) {
|
|||
BENCH(getcontext, bench) {
|
||||
EZBENCH2("get/setcontext", donothing, SetGetContext());
|
||||
}
|
||||
|
||||
BENCH(swapcontext, bench) {
|
||||
ucontext_t main, loop;
|
||||
volatile bool ready = false;
|
||||
getcontext(&main);
|
||||
if (ready) {
|
||||
for (;;) {
|
||||
swapcontext(&main, &loop);
|
||||
// kprintf("boom\n");
|
||||
}
|
||||
} else {
|
||||
ready = true;
|
||||
EZBENCH2("x2 swapcontext", donothing, swapcontext(&loop, &main));
|
||||
// kprintf("dollar\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue