Skip to content
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

Add option for providing an external implementation of clock functions #516

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion core/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* License: <a href="https://github.com/lf-lang/reactor-c/blob/main/LICENSE.md">BSD 2-clause</a>
* @brief Implementations of functions in clock.h.
*/

// By defining the following compile def, the user can provide their own
// implementation of the clock functions. This allows controlling the
// physical time the runtime sees. It is useful for integration with simulators
// or for repeatable test environments.
#if !defined(LF_EXTERNAL_CLOCK_PLUGIN)
#include "clock.h"
#include "low_level_platform.h"

Expand All @@ -18,7 +24,6 @@ void clock_sync_subtract_offset(instant_t* t) { (void)t; }
#endif // defined(FEDERATED)

static instant_t last_read_physical_time = NEVER;

int lf_clock_gettime(instant_t* now) {
instant_t last_read_local;
int res = _lf_clock_gettime(now);
Expand Down Expand Up @@ -57,3 +62,8 @@ int lf_clock_cond_timedwait(lf_cond_t* cond, instant_t wakeup_time) {
return _lf_cond_timedwait(cond, wakeup_time);
}
#endif // !defined(LF_SINGLE_THREADED)
#else // defined(LF_EXTERNAL_CLOCK_PLUGIN)
// The following empty "dummy" function is here to avoid an "Empty translation unit" compiler
// warning if the user has defined LF_EXTERNAL_CLOCK_PLUGIN to provide their own implementation.
void __clock_dummy_function(void) {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using Werror=pedantic which throws an error on empty translation units. This dummy definition avoids that problem.

#endif // !defined(LF_EXTERNAL_CLOCK_PLUGIN)
Loading