mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[util] Add thread id to kernel spinlocks
Expose a function __current_thread_id() and use it to record the thread id on a spinlock waiter when called from the kernel.
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
/// \file spinlock.h
|
||||
/// Spinlock types and related defintions
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user