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