-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider making libcyphal::MonotonicClock meet the requirements of TrivialClock #399
Comments
Scott, sorry but I don't get what is the problem currently. Could you please elaborate and give concrete example where currently implemented approach doesn't fit.
In my numerous unit tests I have everywhere artificial control over time very easy (see
|
As we discussed at the call, one way forward is to define our own #ifndef LIBCYPHAL_CUSTOM_CLOCK_HEADER
// the default implementation that proxies to std::steady_clock
#else
# include LIBCYPHAL_CUSTOM_CLOCK_HEADER
#endif |
An alternative is to define our own |
See https://en.cppreference.com/w/cpp/named_req/TrivialClock
This is a design change, not a bug.
Using chrono becomes tricky when implementing the platform layer because C++ chrono treats system time as a global resource. Furthermore, on some systems chrono clocks are implemented by lower-level (read -> C) clocks also used by the platform implementation. We may want to remove
ITimeProvider
in favor of simply designating a chrono clock all parts of libcyphal will use as a compile-time configuration (with defaults) allowing a given platform to ensure the same timebase by providing a custom chrono clock backed by the low-level implementation for said platform.If libcyphal always uses a compile-time-configured clock then unit testing is just as easy to handle as a dummy clock can be configured for tests when control over time is needed.
There doesn't seem to be another other benefit to supporting polymorphism in our timekeeping mechanism, unless I'm missing something.
The text was updated successfully, but these errors were encountered: