fix a few bugs in scheduling and synchronization, separate OVMF_VARS for debug
This commit is contained in:
1 parent
5cf7a20ea2
commit
129be91e15
17 files changed
+174
-211
No files matched your search
+9
-13
@@ -24,46 +24,42 @@ KSTATUS KeAcquireMutex(MUTEX* mutex) {
|
||||
THREAD* self = KeCurrentThread();
|
||||
|
||||
for (;;) {
|
||||
KeAcquireSpinlock(&mutex->Lock);
|
||||
uintptr_t flags = KeAcquireSpinlock(&mutex->Lock);
|
||||
if (!mutex->Owner) {
|
||||
mutex->Owner = self;
|
||||
KeReleaseSpinlock(&mutex->Lock);
|
||||
KeReleaseSpinlock(&mutex->Lock, flags);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
// Already owned - add self to wait list and block.
|
||||
ListInsertTail(&mutex->WaitList, &self->SchedulerLink);
|
||||
KeReleaseSpinlock(&mutex->Lock);
|
||||
KeReleaseSpinlock(&mutex->Lock, flags);
|
||||
KeBlockThread(self, &mutex->Header);
|
||||
// KeBlockThread calls KeYield; when we return here we've been
|
||||
// unblocked by KeReleaseMutex - loop back and try to own it.
|
||||
}
|
||||
}
|
||||
|
||||
KSTATUS KeTryAcquireMutex(MUTEX* mutex) {
|
||||
if (!mutex) return STATUS_INVALID_PARAMETER;
|
||||
THREAD* self = KeCurrentThread();
|
||||
KeAcquireSpinlock(&mutex->Lock);
|
||||
uintptr_t flags = KeAcquireSpinlock(&mutex->Lock);
|
||||
if (!mutex->Owner) {
|
||||
mutex->Owner = self;
|
||||
KeReleaseSpinlock(&mutex->Lock);
|
||||
KeReleaseSpinlock(&mutex->Lock, flags);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
KeReleaseSpinlock(&mutex->Lock);
|
||||
KeReleaseSpinlock(&mutex->Lock, flags);
|
||||
return STATUS_FAILURE;
|
||||
}
|
||||
|
||||
void KeReleaseMutex(MUTEX* mutex) {
|
||||
if (!mutex) return;
|
||||
KeAcquireSpinlock(&mutex->Lock);
|
||||
uintptr_t flags = KeAcquireSpinlock(&mutex->Lock);
|
||||
mutex->Owner = (struct THREAD *)0;
|
||||
|
||||
// Wake the first waiter, if any.
|
||||
if (!LIST_IS_EMPTY(&mutex->WaitList)) {
|
||||
LIST_ENTRY* node = ListPopHead(&mutex->WaitList);
|
||||
THREAD* waiter = CONTAINING_RECORD(node, THREAD, SchedulerLink);
|
||||
KeReleaseSpinlock(&mutex->Lock);
|
||||
KeReleaseSpinlock(&mutex->Lock, flags);
|
||||
KeUnblockThread(waiter);
|
||||
return;
|
||||
}
|
||||
KeReleaseSpinlock(&mutex->Lock);
|
||||
KeReleaseSpinlock(&mutex->Lock, flags);
|
||||
}
|
||||
Reference in new issue
Block a user