mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 21:28:21 +00:00
cpu: change _cpu()->thread calls to current_thread() to fix smp race
This commit is contained in:
@@ -132,7 +132,7 @@ typedef struct proc_t {
|
||||
|
||||
#include <arch/cpu.h>
|
||||
|
||||
#define UMASK(mode) ((mode) & ~_cpu()->thread->proc->umask)
|
||||
#define UMASK(mode) ((mode) & ~current_thread()->proc->umask)
|
||||
#define PROC_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST)
|
||||
// the acquire of the pid table mutex is done here to prevent a nasty race condition where sched_inactiveproc could be called multiple times
|
||||
// due to the pid table itself not holding any references to the process
|
||||
|
||||
@@ -16,7 +16,7 @@ extern mutex_t printf_mutex;
|
||||
#endif
|
||||
|
||||
#define printf(...) { \
|
||||
if (_cpu()->thread) {\
|
||||
if (current_thread()) {\
|
||||
MUTEX_ACQUIRE(&printf_mutex, false); \
|
||||
} else { \
|
||||
while (MUTEX_TRY(&printf_mutex) == false) CPU_PAUSE(); \
|
||||
|
||||
@@ -56,12 +56,18 @@ static inline uint16_t be_to_cpu_w(uint16_t w) {
|
||||
|
||||
cpu_t *_bsp(void);
|
||||
|
||||
static inline cpu_t *_cpu() {
|
||||
static inline cpu_t *_cpu(void) {
|
||||
cpu_t *cpu;
|
||||
asm volatile ("mov %%gs:8, %%rax" : "=a"(cpu) : : "memory");
|
||||
return cpu;
|
||||
}
|
||||
|
||||
static inline thread_t *current_thread(void) {
|
||||
thread_t *thread;
|
||||
asm volatile ("mov %%gs:0, %%rax" : "=a"(thread) : : "memory");
|
||||
return thread;
|
||||
}
|
||||
|
||||
static inline void cpu_set(cpu_t *ptr) {
|
||||
ptr->self = ptr;
|
||||
wrmsr(MSR_GSBASE, (uint64_t)ptr);
|
||||
|
||||
Reference in New Issue
Block a user