Closed 31415us closed 10 years ago
Yeah, its time to do it. http://stream1.gifsoup.com/view1/1336353/horatio-lunettes-o.gif
More seriously : unsigned int, 32 bits, microseconds ?
+1 for uint32 in us
/** Get a timestamp in microseconds */
uint32_t os_timestamp(void);
/** Updates the timestamp and returns the difference to the previous. */
uint32_t os_timestamp_update(uint32_t *ts);
Something like that?
hmm what happens if you update with a past value? or more precisely what exactly are the responsibilities of os_timestamp_update?
uint32_t os_timestamp_update(uint32_t *ts)
{
uint32_t diff, now;
now = os_timestamp();
diff = now - *ts;
*ts = now;
return diff;
}
I thought this would be a regular use case, so we could implement it in a simple function directly.
I think actually expanding the computation in caller code is more readable.
By the way after a bit of thinking I would split this functionality into two modules : The local timestamp in platform abstraction and the clock sync in the network / bus module. What do you think ?
@antoinealb yeah i agree that it's best to separate those two
We neet two sorts of timestamps anyway. One monotonic for computation and one that is synced. For the monotonic we should have a function like the one nuft proposed, because it will be used a lot. We could find a clearer name for it though.
Maybe something more explicit like timestamp_diff_and_update
.
yes, that looks good
sounds good.
I think timestamp_diff_and_update()
should also be atomic.
It should be enough if the timestamp function is atomic
The timestamp function obviously has to be atomic, doesn't it ?
Well, yes.
at some point we're going to need timestamps to measure time and timedifferences. we should discuss resolutions (milli-, micro-, nano-) and how to achieve synchronization.