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
@@ -25,40 +25,40 @@ KSTATUS KeWaitSemaphore(SEMAPHORE* sem) {
|
||||
THREAD* self = KeCurrentThread();
|
||||
|
||||
for (;;) {
|
||||
KeAcquireSpinlock(&sem->Lock);
|
||||
uintptr_t flags = KeAcquireSpinlock(&sem->Lock);
|
||||
if (sem->Count > 0) {
|
||||
sem->Count--;
|
||||
KeReleaseSpinlock(&sem->Lock);
|
||||
KeReleaseSpinlock(&sem->Lock, flags);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
ListInsertTail(&sem->WaitList, &self->SchedulerLink);
|
||||
KeReleaseSpinlock(&sem->Lock);
|
||||
KeReleaseSpinlock(&sem->Lock, flags);
|
||||
KeBlockThread(self, &sem->Header);
|
||||
}
|
||||
}
|
||||
|
||||
KSTATUS KeTrySemaphore(SEMAPHORE* sem) {
|
||||
if (!sem) return STATUS_INVALID_PARAMETER;
|
||||
KeAcquireSpinlock(&sem->Lock);
|
||||
uintptr_t flags = KeAcquireSpinlock(&sem->Lock);
|
||||
if (sem->Count > 0) {
|
||||
sem->Count--;
|
||||
KeReleaseSpinlock(&sem->Lock);
|
||||
KeReleaseSpinlock(&sem->Lock, flags);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
KeReleaseSpinlock(&sem->Lock);
|
||||
KeReleaseSpinlock(&sem->Lock, flags);
|
||||
return STATUS_FAILURE;
|
||||
}
|
||||
|
||||
void KeSignalSemaphore(SEMAPHORE* sem) {
|
||||
if (!sem) return;
|
||||
KeAcquireSpinlock(&sem->Lock);
|
||||
uintptr_t flags = KeAcquireSpinlock(&sem->Lock);
|
||||
if (!LIST_IS_EMPTY(&sem->WaitList)) {
|
||||
LIST_ENTRY* node = ListPopHead(&sem->WaitList);
|
||||
THREAD* waiter = CONTAINING_RECORD(node, THREAD, SchedulerLink);
|
||||
KeReleaseSpinlock(&sem->Lock);
|
||||
KeReleaseSpinlock(&sem->Lock, flags);
|
||||
KeUnblockThread(waiter);
|
||||
return;
|
||||
}
|
||||
if (sem->Count < sem->MaxCount) sem->Count++;
|
||||
KeReleaseSpinlock(&sem->Lock);
|
||||
KeReleaseSpinlock(&sem->Lock, flags);
|
||||
}
|
||||
Reference in new issue
Block a user