feat(loop): add EventLoopService (dispatcher drain + timer wheel)#30
Merged
Conversation
…ty via ITimerWheelDriver
| var dispatcher = new MainThreadDispatcherService(); | ||
| var timer = new FakeTimerService(); | ||
| using var loop = new EventLoopService(dispatcher, timer, new EventLoopConfig()); | ||
| var signal = new ManualResetEventSlim(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports Moongate's
GameLoopServiceinto SquidStd as a general-purposeEventLoopService: a dedicated background thread (SquidStd-EventLoop) that each frame drains theIMainThreadDispatcherand advances the timer wheel (ITimerService.UpdateTicksDelta), idle-sleeps when a tick produced no work, exposes tick metrics viaIMetricProvider, and warns on slow ticks.Opt-in via
RegisterEventLoop()and mutually exclusive withTimerWheelPumpService— both advance the timer wheel, so a sharedITimerWheelDrivermarker makes the exclusivity structural.Changes
SquidStd.Core):IEventLoopService(pure — Core doesn't reference Abstractions),ITimerWheelDrivermarker,EventLoopConfig(IdleCpuEnabled/IdleSleepMs/SlowTickThresholdMs).EventLoopService(SquidStd.Services.Core): implementsIEventLoopService, ISquidStdService, IMetricProvider, ITimerWheelDriver, IDisposable;internal Tick()extracted for deterministic tests.RegisterEventLoop(): fail-fast if a timer-wheel driver is already registered; maps the loop toITimerWheelDriverandIMetricProvider.TimerWheelPumpServicenow implementsITimerWheelDriver; the three pump registration sites map the marker, and the WorkerManager/Mail guards switched fromIsRegistered<TimerWheelPumpService>()toIsRegistered<ITimerWheelDriver>()— so registering the event loop suppresses the pump auto-registration (no double wheel advance).Test Plan
Tick()drains dispatcher, advances the timer wheel, returns work; idle path; metrics prefixeventloop; start/stop thread executes posted work (5 tests)IMetricProviderappears in theIEnumerable<IMetricProvider>collection and is the SAME singleton; mutual exclusivity holds both directions