Skip to content

Conversation

@NewYaroslav
Copy link
Owner

Motivation

  • Replace the previous ad-hoc singleton storage with a robust "eternal" singleton pattern that supports both header-only and DLL-backed singletons.
  • Allow a single process-wide instance when building as a DLL to avoid ODR/multiple-instance issues.
  • Keep changes minimal and localized to ntp_time_service.hpp and tests.
  • Add an automated check that the DLL-singleton path compiles/links correctly under ODR test scenarios.

Description

  • Introduced a detail::NtpTimeServiceSingleton template and switched NtpTimeServiceT::instance() to return detail::NtpTimeServiceSingleton<RunnerT>::instance().
  • Added optional DLL macros: TIME_SHIELD_NTP_TIME_SERVICE_USE_DLL_SINGLETON, TIME_SHIELD_NTP_TIME_SERVICE_DLL_EXPORTS, and TIME_SHIELD_NTP_TIME_SERVICE_DLL_IMPLEMENTATION and TIME_SHIELD_NTP_TIME_SERVICE_API to control exported ntp_time_service_instance() linkage.
  • Implemented the DLL-exported ntp_time_service_instance() (when DLL_IMPLEMENTATION is defined) and kept the header-only eternal-allocated instance as the default.
  • Updated tests: removed the old define from tests/ntp_time_service_test.cpp, added ODR test sources tests/odr/ntp_time_service_dll_a.cpp and tests/odr/ntp_time_service_dll_b.cpp, and wired them into tests/odr/CMakeLists.txt to validate the DLL-singleton code path.

Testing

  • Configured tests and generated build files with cmake -S . -B build -DTIME_SHIELD_CPP_BUILD_TESTS=ON and configure succeeded.
  • Built the project with cmake --build build and the build completed successfully.
  • Executed tests with ctest --test-dir build and all tests passed (36/36).
  • The new ODR/DLL test target ntp_time_service_dll_odr was built and ran as part of the test suite.

Codex Task

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants