mirror of https://gitlab.com/nakst/essence
introduce activeTimersSpinlock
This commit is contained in:
parent
095ff182a2
commit
cbedfce554
|
@ -235,6 +235,7 @@ struct Scheduler {
|
|||
|
||||
KSpinlock lock; // The general lock. TODO Break this up!
|
||||
KMutex allThreadsMutex; // For accessing the allThreads list.
|
||||
KSpinlock activeTimersSpinlock; // For accessing the activeTimers lists.
|
||||
|
||||
KEvent killedEvent; // Set during shutdown when all processes have been terminated.
|
||||
uintptr_t blockShutdownProcessCount;
|
||||
|
@ -1280,6 +1281,7 @@ void Scheduler::Yield(InterruptContext *context) {
|
|||
globalData->schedulerTimeMs = timeMs;
|
||||
|
||||
// Notify the necessary timers.
|
||||
KSpinlockAcquire(&activeTimersSpinlock);
|
||||
LinkedItem<KTimer> *_timer = activeTimers.firstItem;
|
||||
|
||||
while (_timer) {
|
||||
|
@ -1299,6 +1301,8 @@ void Scheduler::Yield(InterruptContext *context) {
|
|||
|
||||
_timer = next;
|
||||
}
|
||||
|
||||
KSpinlockRelease(&activeTimersSpinlock);
|
||||
}
|
||||
|
||||
// Get the next thread to execute.
|
||||
|
|
|
@ -572,8 +572,7 @@ void TestWriterLocks() {
|
|||
#endif
|
||||
|
||||
void KTimerSet(KTimer *timer, uint64_t triggerInMs, KAsyncTaskCallback _callback, EsGeneric _argument) {
|
||||
KSpinlockAcquire(&scheduler.lock);
|
||||
EsDefer(KSpinlockRelease(&scheduler.lock));
|
||||
KSpinlockAcquire(&scheduler.activeTimersSpinlock);
|
||||
|
||||
// Reset the timer state.
|
||||
|
||||
|
@ -610,11 +609,12 @@ void KTimerSet(KTimer *timer, uint64_t triggerInMs, KAsyncTaskCallback _callback
|
|||
} else {
|
||||
scheduler.activeTimers.InsertEnd(&timer->item);
|
||||
}
|
||||
|
||||
KSpinlockRelease(&scheduler.activeTimersSpinlock);
|
||||
}
|
||||
|
||||
void KTimerRemove(KTimer *timer) {
|
||||
KSpinlockAcquire(&scheduler.lock);
|
||||
EsDefer(KSpinlockRelease(&scheduler.lock));
|
||||
KSpinlockAcquire(&scheduler.activeTimersSpinlock);
|
||||
|
||||
if (timer->callback) {
|
||||
KernelPanic("KTimer::Remove - Timers with callbacks cannot be removed.\n");
|
||||
|
@ -623,6 +623,8 @@ void KTimerRemove(KTimer *timer) {
|
|||
if (timer->item.list) {
|
||||
scheduler.activeTimers.Remove(&timer->item);
|
||||
}
|
||||
|
||||
KSpinlockRelease(&scheduler.activeTimersSpinlock);
|
||||
}
|
||||
|
||||
void Scheduler::WaitMutex(KMutex *mutex) {
|
||||
|
|
Loading…
Reference in New Issue