-
Notifications
You must be signed in to change notification settings - Fork 291
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 support for setting a custom monotonic time function in mono_time #1123
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1123 +/- ##
========================================
+ Coverage 82.5% 82.6% +0.1%
========================================
Files 81 81
Lines 14414 14437 +23
========================================
+ Hits 11895 11929 +34
+ Misses 2519 2508 -11
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 approvals obtained (waiting on @zugz)
toxcore/mono_time.h, line 62 at r1 (raw file):
* to increase monotonically. */ void set_time_monotonic_callback(Mono_Time *mono_time,
Let's name this something starting with "mono_time", so this file is more api-standard compliant. We try to place functions belonging to a module in the same "namespace". (Same for the cb above)
toxcore/mono_time.c, line 78 at r1 (raw file):
{ if (time_monotonic_callback == nullptr) { time_monotonic_callback = current_time_monotonic_default;
nit: assigning a parameter is not great. Assignment is generally icky, but parameter assignment is often considered bad style (in JavaScript, it's a really bad idea, in other languages it's just a little frowned upon). Let's put if (..) { mono_time->tmc = ..; } else { mono_time->tmc = ctmd; }
instead.
@zugz can you add a test for this functionality to mono_time_test.cc? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 3 files at r2.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @zugz)
toxcore/mono_time.c, line 47 at r2 (raw file):
mono_time->time = 0; mono_time->current_time_callback = current_time_monotonic_default;
Move this one line down, so initialisation of the fields happens in declaration order and so the callback-related fields are initialised together.
toxcore/mono_time.c, line 85 at r2 (raw file):
} mono_time->user_data = user_data;
Move this to the second branch, and add an assignment of nullptr to the first branch. This way we avoid pointing at user data when nothing will ever be able to read it.
toxcore/mono_time_test.cc, line 48 at r2 (raw file):
uint64_t test_time = 42137; mono_time_set_current_time_callback(mono_time, test_current_time_callback, &test_time);
test_current_time_callback
is probably better as a lambda: [](void *user_data) { return *(uint64_t *)user_data; }
.
Move this one line down
The initialisation of base_time involves calling current_time_monotonic,
which expects current_time_callback to be set.
We could have current_time_monotonic use default if
current_time_callback is NULL, but current_time_monotonic may be called
frequently so it might be best to avoid branches?
`test_current_time_callback` is probably better as a lambda:
Maybe better to stick to pure C, since this doubles as soft
documentation on how to use the callback functionality?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r3.
Reviewable status: 1 change requests, 0 of 1 approvals obtained
toxcore/mono_time.c, line 47 at r2 (raw file):
Previously, iphydf wrote…
Move this one line down, so initialisation of the fields happens in declaration order and so the callback-related fields are initialised together.
Ok, can you move the callback initialisation code up then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 1 of 1 approvals obtained (waiting on @zugz)
toxcore/mono_time.c, line 47 at r2 (raw file):
Previously, iphydf wrote…
Ok, can you move the callback initialisation code up then?
Unresolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r4.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @zugz)
6566fb8
to
01e2cc5
Compare
Ok, can you move the callback initialisation code up then?
Done
|
(derived from #1095)
This change is