mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14: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:
@@ -180,3 +180,10 @@ thread::create_idle_thread(process &kernel, uintptr_t rsp0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace obj
|
} // namespace obj
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
__current_thread_id()
|
||||||
|
{
|
||||||
|
cpu_data &cpu = current_cpu();
|
||||||
|
return cpu.thread ? cpu.thread->obj_id() : -1u;
|
||||||
|
}
|
||||||
|
|||||||
@@ -207,3 +207,5 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace obj
|
} // namespace obj
|
||||||
|
|
||||||
|
extern "C" uint32_t __current_thread_id();
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
/// \file spinlock.h
|
/// \file spinlock.h
|
||||||
/// Spinlock types and related defintions
|
/// Spinlock types and related defintions
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __j6kernel
|
||||||
|
extern "C" uint32_t __current_thread_id();
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
/// An MCS based spinlock
|
/// An MCS based spinlock
|
||||||
@@ -18,6 +23,7 @@ public:
|
|||||||
bool blocked;
|
bool blocked;
|
||||||
waiter *next;
|
waiter *next;
|
||||||
char const *where;
|
char const *where;
|
||||||
|
uint32_t thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool try_acquire(waiter *w);
|
bool try_acquire(waiter *w);
|
||||||
@@ -36,7 +42,7 @@ public:
|
|||||||
spinlock &lock,
|
spinlock &lock,
|
||||||
const char *where = __builtin_FUNCTION()) :
|
const char *where = __builtin_FUNCTION()) :
|
||||||
m_lock(lock),
|
m_lock(lock),
|
||||||
m_waiter {false, nullptr, where},
|
m_waiter {false, nullptr, where, get_thread()},
|
||||||
m_is_locked {false}
|
m_is_locked {false}
|
||||||
{
|
{
|
||||||
m_lock.acquire(&m_waiter);
|
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:
|
private:
|
||||||
spinlock &m_lock;
|
spinlock &m_lock;
|
||||||
spinlock::waiter m_waiter;
|
spinlock::waiter m_waiter;
|
||||||
|
|||||||
Reference in New Issue
Block a user