mirror of
https://github.com/justinian/jsix.git
synced 2025-12-11 08:54:31 -08:00
[kernel] Add userspace threading
Implement the syscalls necessary for threads to create other threads in their same process. This involved rearranging a number of syscalls, as well as implementing object_wait and a basic implementation of a process' list of handles.
This commit is contained in:
@@ -3,32 +3,53 @@
|
||||
|
||||
#include "j6/types.h"
|
||||
#include "j6/errors.h"
|
||||
#include "j6/signals.h"
|
||||
|
||||
extern "C" {
|
||||
j6_status_t get_process_koid(j6_koid_t *koid);
|
||||
j6_status_t sleep(uint64_t til);
|
||||
j6_status_t debug();
|
||||
j6_status_t message(const char *msg);
|
||||
j6_status_t system_log(const char *msg);
|
||||
|
||||
j6_status_t object_wait(j6_handle_t obj, j6_signal_t sig, j6_signal_t *out);
|
||||
|
||||
j6_status_t process_koid(j6_koid_t *koid);
|
||||
|
||||
j6_status_t thread_koid(j6_koid_t *koid);
|
||||
j6_status_t thread_create(void (*koid)(), j6_handle_t *handle);
|
||||
j6_status_t thread_sleep(uint64_t til);
|
||||
j6_status_t thread_exit(int64_t status);
|
||||
|
||||
int main(int, const char **);
|
||||
}
|
||||
|
||||
void
|
||||
thread_proc()
|
||||
{
|
||||
system_log("sub thread starting");
|
||||
for (int i = 1; i < 5; ++i)
|
||||
thread_sleep(i*10);
|
||||
|
||||
system_log("sub thread exiting");
|
||||
thread_exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
uint64_t pid = 0;
|
||||
uint64_t child = 0;
|
||||
j6_koid_t process = 0;
|
||||
j6_handle_t child = 0;
|
||||
j6_signal_t out = 0;
|
||||
|
||||
j6_status_t result = get_process_koid(&process);
|
||||
system_log("main thread starting");
|
||||
|
||||
j6_status_t result = thread_create(&thread_proc, &child);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
message("hello from nulldrv!");
|
||||
system_log("main thread waiting on child");
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
sleep(i*10);
|
||||
result = object_wait(child, -1ull, &out);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
return pid;
|
||||
system_log("main thread done, exiting");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user