Nice wrappers around process management
All checks were successful
Build documentation / build-and-deploy (push) Successful in 34s

This commit is contained in:
2026-01-29 00:08:54 +01:00
parent 1c64d608bd
commit 388418a718
7 changed files with 63 additions and 35 deletions

View File

@@ -1,45 +1,15 @@
#include <alloc/liballoc.h>
#include <limits.h>
#include <m/status.h>
#include <m/system.h>
#include <proc/local.h>
#include <proc/proc.h>
#include <stddef.h>
#include <stdint.h>
#include <string/string.h>
#define MUTEX 2000
__thread char letter = 'c';
LOCAL char letter = 'c';
void app_thread1 (void);
int spawn (void (*fn) (void)) {
size_t stack_size = 256 * PAGE_SIZE;
void* stack = malloc (stack_size);
if (stack == NULL)
return -ST_OOM_ERROR;
uintptr_t stack_top = (uintptr_t)stack + stack_size;
return clone (stack_top, fn);
}
void app_main (void) {
mutex_create (MUTEX);
letter = 'a';
spawn (&app_thread1);
for (;;) {
mutex_lock (MUTEX);
for (int i = 0; i < 3; i++)
test (letter);
mutex_unlock (MUTEX);
}
}
void app_thread1 (void) {
void app_proc1 (void) {
letter = 'b';
for (;;) {
@@ -51,5 +21,22 @@ void app_thread1 (void) {
mutex_unlock (MUTEX);
}
quit ();
process_quit ();
}
void app_main (void) {
mutex_create (MUTEX);
letter = 'a';
process_spawn (&app_proc1);
for (;;) {
mutex_lock (MUTEX);
for (int i = 0; i < 3; i++)
test (letter);
mutex_unlock (MUTEX);
}
}