Add debug log to cosmoaudio and add examples

This commit is contained in:
Justine Tunney 2024-09-11 02:14:38 -07:00
parent a5c0189bf6
commit 0f3457c172
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
38 changed files with 504 additions and 371 deletions

View file

@ -7,12 +7,9 @@
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/calls/calls.h"
#include "libc/calls/ucontext.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/exit.h"
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
/**
* @fileoverview swapcontext() and makecontext() example
@ -33,18 +30,16 @@ static ucontext_t uctx_func2;
static void func1(void) {
say("func1: started\n");
say("func1: swapcontext(&uctx_func1, &uctx_func2)\n");
if (swapcontext(&uctx_func1, &uctx_func2) == -1) {
if (swapcontext(&uctx_func1, &uctx_func2) == -1)
handle_error("swapcontext");
}
say("func1: returning\n");
}
static void func2(void) {
say("func2: started\n");
say("func2: swapcontext(&uctx_func2, &uctx_func1)\n");
if (swapcontext(&uctx_func2, &uctx_func1) == -1) {
if (swapcontext(&uctx_func2, &uctx_func1) == -1)
handle_error("swapcontext");
}
say("func2: returning\n");
}
@ -52,17 +47,15 @@ int main(int argc, char *argv[]) {
char func1_stack[8192];
char func2_stack[8192];
if (getcontext(&uctx_func1) == -1) {
if (getcontext(&uctx_func1) == -1)
handle_error("getcontext");
}
uctx_func1.uc_stack.ss_sp = func1_stack;
uctx_func1.uc_stack.ss_size = sizeof(func1_stack);
uctx_func1.uc_link = &uctx_main;
makecontext(&uctx_func1, func1, 0);
if (getcontext(&uctx_func2) == -1) {
if (getcontext(&uctx_func2) == -1)
handle_error("getcontext");
}
uctx_func2.uc_stack.ss_sp = func2_stack;
uctx_func2.uc_stack.ss_size = sizeof(func2_stack);
/* Successor context is f1(), unless argc > 1 */
@ -70,9 +63,8 @@ int main(int argc, char *argv[]) {
makecontext(&uctx_func2, func2, 0);
say("main: swapcontext(&uctx_main, &uctx_func2)\n");
if (swapcontext(&uctx_main, &uctx_func2) == -1) {
if (swapcontext(&uctx_main, &uctx_func2) == -1)
handle_error("swapcontext");
}
say("main: exiting\n");
exit(EXIT_SUCCESS);