msgblock: Add new clock_fill() function

Add a new function for filling the fields of 'struct clock_estimate'.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2025-09-18 15:11:20 -04:00
parent 13cfdf5711
commit a66f5cec52
3 changed files with 14 additions and 4 deletions

View File

@@ -207,3 +207,14 @@ clock_from_time(struct clock_estimate *ce, double time)
{
return (int64_t)((time - ce->conv_time)*ce->est_freq + .5) + ce->conv_clock;
}
// Fill the fields of a 'struct clock_estimate'
void
clock_fill(struct clock_estimate *ce, double est_freq, double conv_time
, uint64_t conv_clock, uint64_t last_clock)
{
ce->est_freq = est_freq;
ce->conv_time = conv_time;
ce->conv_clock = conv_clock;
ce->last_clock = last_clock;
}

View File

@@ -50,5 +50,7 @@ void message_queue_free(struct list_head *root);
uint64_t clock_from_clock32(struct clock_estimate *ce, uint32_t clock32);
double clock_to_time(struct clock_estimate *ce, uint64_t clock);
uint64_t clock_from_time(struct clock_estimate *ce, double time);
void clock_fill(struct clock_estimate *ce, double est_freq, double conv_time
, uint64_t conv_clock, uint64_t last_clock);
#endif // msgblock.h

View File

@@ -909,10 +909,7 @@ serialqueue_set_clock_est(struct serialqueue *sq, double est_freq
, uint64_t last_clock)
{
pthread_mutex_lock(&sq->lock);
sq->ce.est_freq = est_freq;
sq->ce.conv_time = conv_time;
sq->ce.conv_clock = conv_clock;
sq->ce.last_clock = last_clock;
clock_fill(&sq->ce, est_freq, conv_time, conv_clock, last_clock);
pthread_mutex_unlock(&sq->lock);
}