diff --git a/src/kernel/objects/thread.cpp b/src/kernel/objects/thread.cpp index f83377a..351b85e 100644 --- a/src/kernel/objects/thread.cpp +++ b/src/kernel/objects/thread.cpp @@ -180,3 +180,10 @@ thread::create_idle_thread(process &kernel, uintptr_t rsp0) } } // namespace obj + +uint32_t +__current_thread_id() +{ + cpu_data &cpu = current_cpu(); + return cpu.thread ? cpu.thread->obj_id() : -1u; +} diff --git a/src/kernel/objects/thread.h b/src/kernel/objects/thread.h index c99c7c2..cc320af 100644 --- a/src/kernel/objects/thread.h +++ b/src/kernel/objects/thread.h @@ -207,3 +207,5 @@ private: }; } // namespace obj + +extern "C" uint32_t __current_thread_id(); diff --git a/src/libraries/util/util/spinlock.h b/src/libraries/util/util/spinlock.h index aabb963..dedad83 100644 --- a/src/libraries/util/util/spinlock.h +++ b/src/libraries/util/util/spinlock.h @@ -1,8 +1,13 @@ /// \file spinlock.h /// Spinlock types and related defintions - #pragma once +#include + +#ifdef __j6kernel +extern "C" uint32_t __current_thread_id(); +#endif + namespace util { /// An MCS based spinlock @@ -18,6 +23,7 @@ public: bool blocked; waiter *next; char const *where; + uint32_t thread; }; bool try_acquire(waiter *w); @@ -36,7 +42,7 @@ public: spinlock &lock, const char *where = __builtin_FUNCTION()) : m_lock(lock), - m_waiter {false, nullptr, where}, + m_waiter {false, nullptr, where, get_thread()}, m_is_locked {false} { m_lock.acquire(&m_waiter); @@ -61,6 +67,14 @@ public: } } + inline uint32_t get_thread() const { +#ifdef __j6kernel + return __current_thread_id(); +#else + return -1u; +#endif + } + private: spinlock &m_lock; spinlock::waiter m_waiter;