cpu: change _cpu()->thread calls to current_thread() to fix smp race

This commit is contained in:
Matheus
2024-09-15 17:47:26 -03:00
parent d1c0f2a5fd
commit e058d62261
65 changed files with 196 additions and 190 deletions
+3 -3
View File
@@ -34,7 +34,7 @@ static thread_t *get(semaphore_t *sem) {
}
static void removeself(semaphore_t *sem) {
thread_t *thread = _cpu()->thread;
thread_t *thread = current_thread();
// first see if we have been removed already
if ((sem->head == NULL && sem->tail == NULL) || // no threads in sleep list
@@ -59,7 +59,7 @@ static void removeself(semaphore_t *sem) {
}
int semaphore_wait(semaphore_t *sem, bool interruptible) {
if (_cpu()->thread == NULL) {
if (current_thread() == NULL) {
while (semaphore_test(sem) == false) CPU_PAUSE();
return 0;
}
@@ -69,7 +69,7 @@ int semaphore_wait(semaphore_t *sem, bool interruptible) {
spinlock_acquire(&sem->lock);
if (--sem->i < 0) {
insert(sem, _cpu()->thread);
insert(sem, current_thread());
sched_preparesleep(interruptible);
spinlock_release(&sem->lock);
ret = sched_yield();