-
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
chrono clock should be defined in config.hpp #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 |
I've just had the best idea (no really, don't argue, this is the best idea ;-) ) We should define the clock type in config.hpp (see #419) so we can use the application's native timepoint representation and avoid unnecessary division operations. I'm running into this now where the ratio and representation for time on FreeRTOS is different so every use of time by libcyphal has to translate even before it knows the value is needed or that the native format is (would have been) okay. |
I changed the name of this issue because, as I implement FreeRTOS support, I'm realizing this problem is worse than I originally thought. libcyphal dictates a |
Making this high-priority because the change will have a large blast radius. The more we use this library the harder it's going to be to change this. |
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: