From cdbad56ed71e939c87674ca11c1a6f3bbee2b5f1 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 2 Feb 2023 23:26:19 +0200 Subject: [PATCH] Kernel: Update shell thread command to run following command as thread 'thread echo "Hello World"' runs the command 'echo "Hello World"' after 5 seconds have passed. This was just my test code for threading --- kernel/kernel/Shell.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index f49ef1ac..d7a87209 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -182,29 +182,29 @@ argument_done: } else if (arguments.front() == "thread") { - if (arguments.size() != 1) - { - TTY_PRINTLN("'thread' does not support command line arguments"); - return; - } - //Scheduler::Get().AddThread( - // [this, arguments]() - // { - // auto start = PIT::ms_since_boot(); - // while (PIT::ms_since_boot() < start + 5000); - // auto copy = arguments; - // copy.remove(0); - // ProcessCommand(copy); - // } - //); - Scheduler::get().add_thread(BAN::Function( - [this]() + static SpinLock s_thread_spinlock; + + // NOTE: This is a workaround to pass values as copies to threads. + // I have only implemented passing integer and pointers. + // We don't continue execution until the thread has unlocked + // the spinlock. + s_thread_spinlock.lock(); + Scheduler::get().add_thread(Function*)>( + [this] (const Vector* args_ptr) { + auto args = *args_ptr; + s_thread_spinlock.unlock(); + + args.remove(0); + auto start = PIT::ms_since_boot(); - while (PIT::ms_since_boot() < start + 3000); - TTY_PRINTLN("hello"); + while (PIT::ms_since_boot() < start + 5000); + + process_command(args); } - )); + ), &arguments); + + while (s_thread_spinlock.is_locked()); } else if (arguments.front() == "memory") {