feat(ntp): eternal singleton for NtpTimeService with optional DLL linkage#113
Open
NewYaroslav wants to merge 7 commits intomainfrom
Open
feat(ntp): eternal singleton for NtpTimeService with optional DLL linkage#113NewYaroslav wants to merge 7 commits intomainfrom
NewYaroslav wants to merge 7 commits intomainfrom
Conversation
Refactor the NTP time service to use the eternal singleton pattern with optional DLL support. Add an ODR test target covering DLL singleton macros and adjust test setup.
Add state and condition variable coordination to prevent concurrent runner starts. Ensure init, shutdown, and config reload wait for in-flight startup and cleanly roll back on failure.
Register atexit shutdown for the eternal singleton and store a cached offset. Avoid implicit startup in time getters and update tests to start explicitly.
Rename the exported DLL singleton symbol for NtpTimeService and document ABI expectations. Adjust stale age arithmetic and init return documentation; fix a macro comment typo.
Move condition variable notifications out of locked sections and add a cached offset fast path. Document DLL shutdown guidance and note UTC fallback behavior.
Simplify init notifications, streamline offset_us caching, and prevent apply_config_now from clearing a running runner when build fails.
Drop an unused should_notify assignment in apply_config_now and keep a single post-update notification.
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.
Motivation
ntp_time_service.hppand tests.Description
detail::NtpTimeServiceSingletontemplate and switchedNtpTimeServiceT::instance()to returndetail::NtpTimeServiceSingleton<RunnerT>::instance().TIME_SHIELD_NTP_TIME_SERVICE_USE_DLL_SINGLETON,TIME_SHIELD_NTP_TIME_SERVICE_DLL_EXPORTS, andTIME_SHIELD_NTP_TIME_SERVICE_DLL_IMPLEMENTATIONandTIME_SHIELD_NTP_TIME_SERVICE_APIto control exportedntp_time_service_instance()linkage.ntp_time_service_instance()(whenDLL_IMPLEMENTATIONis defined) and kept the header-only eternal-allocated instance as the default.tests/ntp_time_service_test.cpp, added ODR test sourcestests/odr/ntp_time_service_dll_a.cppandtests/odr/ntp_time_service_dll_b.cpp, and wired them intotests/odr/CMakeLists.txtto validate the DLL-singleton code path.Testing
cmake -S . -B build -DTIME_SHIELD_CPP_BUILD_TESTS=ONand configure succeeded.cmake --build buildand the build completed successfully.ctest --test-dir buildand all tests passed (36/36).ntp_time_service_dll_odrwas built and ran as part of the test suite.Codex Task