Add kernel threading test
Kernel multithreading is working! Threads cannot exit for now. Scheduling is round-robin for now.
This commit is contained in:
parent
58a74e4859
commit
fbaf9df59f
@ -225,5 +225,6 @@ public extern(C) ulong * isr(ulong vector, ulong * stack_frame)
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread.current_thread = Thread.current_thread.list_next;
|
||||
return Thread.current_thread.stack_pointer;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import hulk.klog;
|
||||
import hulk.list;
|
||||
import hulk.time;
|
||||
import hulk.hurl.a1;
|
||||
import hulk.thread;
|
||||
import core.volatile;
|
||||
|
||||
struct Test
|
||||
{
|
||||
@ -18,6 +20,7 @@ struct Test
|
||||
Klog.writefln("\a3Running kernel tests");
|
||||
test_pit();
|
||||
test_list();
|
||||
test_threads();
|
||||
Klog.writefln("\a3Kernel tests complete");
|
||||
}
|
||||
|
||||
@ -120,6 +123,44 @@ struct Test
|
||||
assert_eq(1, s3.list_count);
|
||||
}
|
||||
|
||||
private static __gshared ubyte thread_test_done;
|
||||
|
||||
private static void test_threads()
|
||||
{
|
||||
static void t1()
|
||||
{
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
Klog.writefln("thread 1");
|
||||
Time.msleep(2000u);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
static void t2()
|
||||
{
|
||||
Time.msleep(1000u);
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
Klog.writefln("thread 2");
|
||||
Time.msleep(2000u);
|
||||
}
|
||||
volatileStore(&thread_test_done, 1);
|
||||
for (;;)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Thread.start(&t1);
|
||||
Thread.start(&t2);
|
||||
|
||||
while (volatileLoad(&thread_test_done) == 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void assert_eq(T)(T first, T second, size_t line_number = __LINE__)
|
||||
{
|
||||
if (first != second)
|
||||
|
@ -66,6 +66,7 @@ struct Thread
|
||||
{
|
||||
threads = &this;
|
||||
}
|
||||
list_insert_after(current_thread);
|
||||
stack_addr = A1.allocate(STACK_SIZE);
|
||||
ulong * stack_top = cast(ulong *)(stack_addr + STACK_SIZE);
|
||||
stack_pointer = stack_top - Idt.ISF_COUNT;
|
||||
|
Loading…
x
Reference in New Issue
Block a user