2.2 KiB
2.2 KiB
Time Injected Clocks and Bounded Stopwatch
Task ID: M-TIME-02 Phase: P1 Status: APPROVED Contracts: C-01, C-04, C-05
1. Context and baseline
include/Void/Time/Stopwatch.hpp hardcodes std::chrono::steady_clock::now(), grows laps_ without bound, and lacks resume(). No injectable MonotonicClock / CivilClock / ManualClock interface exists yet for deterministic testing or Async deadlines.
2. Deliverables
include/Void/Time/Clock.hpp(MonotonicClock,CivilClock,SystemMonotonicClock,SystemCivilClock,ManualClock,ManualCivilClock,remaining_until).- Updated clock-injectable, bounded
Stopwatch(resume, single-samplesplit,try_lapcapped at 4,096) andScopedTimerclock overload ininclude/Void/Time/Stopwatch.hpp. tests/standalone/Time/Clock.cppand deterministic tests intests/standalone/Time/Stopwatch.cpp.
3. Exact files and interfaces
include/Void/Time/Clock.hpp: atomic nanosecond storage inManualClock/ManualCivilClock, checkedadvance(negative_step,overflow), monotonicsetinManualClock,remaining_until(clock, deadline).include/Void/Time/Stopwatch.hpp:StopwatchError { not_running, lap_limit_reached },kDefaultMaxLaps = 4096, borrowedMonotonicClockconstructors,resume(),try_lap(), single-samplesplit(), legacylap()compatibility.
4. Edge cases
ManualClock::advancewith negative duration orINT64_MAXoverflow leaves time unchanged and returnsClockError.Stopwatch::start() -> stop() -> advance(clock) -> resume()preserves prior elapsed & laps without counting stopped idle time.try_lap()atmax_laps_returnslap_limit_reachedwithout growinglaps_.
5. Acceptance criteria
- Existing sleep-based
Time/Stopwatchtests pass; deterministicManualClocktests run with zero sleeps under-Werror.
6. Verification commands
dev cpp-gcc -c cmake -S . -B /tmp/void-p1-time -G Ninja -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Time;Testing" -DVOID_WARNINGS_AS_ERRORS=ON
dev cpp-gcc -c cmake --build /tmp/void-p1-time --parallel 4
dev cpp-gcc -c /tmp/void-p1-time/tests/VoidTests --filter "Clock*|Stopwatch*|Time*"