From cfe706f0328c1e687b3d0b0091f8fafc4c15ee17 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 18 Aug 2016 12:10:09 +0200 Subject: [PATCH] util: modify UTI_*ToDouble functions to return double directly --- keys.c | 2 +- manual.c | 6 +++--- ntp_core.c | 4 ++-- ntp_signd.c | 2 +- ntp_sources.c | 2 +- refclock.c | 6 +++--- refclock_phc.c | 6 +++--- refclock_shm.c | 2 +- reference.c | 8 ++++---- rtc_linux.c | 2 +- sched.c | 10 +++++----- smooth.c | 4 ++-- sources.c | 2 +- sourcestats.c | 23 +++++++++++------------ sys_generic.c | 6 +++--- sys_macosx.c | 14 +++++++------- sys_netbsd.c | 4 ++-- util.c | 28 +++++++++++++--------------- util.h | 6 +++--- 19 files changed, 67 insertions(+), 70 deletions(-) diff --git a/keys.c b/keys.c index 1ec5f67..a8577d6 100644 --- a/keys.c +++ b/keys.c @@ -113,7 +113,7 @@ determine_hash_delay(uint32_t key_id) (unsigned char *)&pkt.auth_data, sizeof (pkt.auth_data)); LCL_ReadRawTime(&after); - UTI_DiffTimespecsToDouble(&diff, &after, &before); + diff = UTI_DiffTimespecsToDouble(&after, &before); if (i == 0 || min_diff > diff) min_diff = diff; diff --git a/manual.c b/manual.c index ca3a249..4124234 100644 --- a/manual.c +++ b/manual.c @@ -110,7 +110,7 @@ estimate_and_set_system(struct timespec *now, int offset_provided, double offset if (n_samples > 1) { for (i=0; ilocal_tx); + last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx); if (last_tx < 0.0) last_tx = 0.0; delay = get_transmit_delay(inst, 0, 0.0) - last_tx; @@ -1346,7 +1346,7 @@ receive_packet(NTP_Packet *message, struct timespec *now, double now_err, NCR_In /* Calculate offset. Following the NTP definition, this is negative if we are fast of the remote source. */ - UTI_DiffTimespecsToDouble(&offset, &remote_average, &local_average); + offset = UTI_DiffTimespecsToDouble(&remote_average, &local_average); /* Apply configured correction */ offset += inst->offset_correction; diff --git a/ntp_signd.c b/ntp_signd.c index 9080e23..9e81f49 100644 --- a/ntp_signd.c +++ b/ntp_signd.c @@ -186,7 +186,7 @@ process_response(SignInstance *inst) } SCH_GetLastEventTime(NULL, NULL, &ts); - UTI_DiffTimespecsToDouble(&delay, &ts, &inst->request_ts); + delay = UTI_DiffTimespecsToDouble(&ts, &inst->request_ts); DEBUG_LOG(LOGF_NtpSignd, "Signing succeeded (delay %f)", delay); diff --git a/ntp_sources.c b/ntp_sources.c index abc28da..c5251ae 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -702,7 +702,7 @@ NSR_HandleBadSource(IPAddr *address) /* Don't resolve names too frequently */ SCH_GetLastEventTime(NULL, NULL, &now); - UTI_DiffTimespecsToDouble(&diff, &now, &last_replacement); + diff = UTI_DiffTimespecsToDouble(&now, &last_replacement); if (fabs(diff) < RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) { DEBUG_LOG(LOGF_NtpSources, "replacement postponed"); return; diff --git a/refclock.c b/refclock.c index 1f9c9b4..fdd9df3 100644 --- a/refclock.c +++ b/refclock.c @@ -442,7 +442,7 @@ RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second) ref_dispersion += filter_get_avg_sample_dispersion(&lock_refclock->filter); - UTI_DiffTimespecsToDouble(&sample_diff, &cooked_time, &ref_sample_time); + sample_diff = UTI_DiffTimespecsToDouble(&cooked_time, &ref_sample_time); if (fabs(sample_diff) >= 2.0 / rate) { DEBUG_LOG(LOGF_Refclock, "refclock pulse ignored samplediff=%.9f", sample_diff); @@ -509,7 +509,7 @@ valid_sample_time(RCL_Instance instance, struct timespec *ts) double diff; LCL_ReadRawTime(&raw_time); - UTI_DiffTimespecsToDouble(&diff, &raw_time, ts); + diff = UTI_DiffTimespecsToDouble(&raw_time, ts); if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1)) { DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f ts=%s", UTI_RefidToString(instance->ref_id), diff, UTI_TimespecToString(ts)); @@ -838,7 +838,7 @@ filter_get_sample(struct MedianFilter *filter, struct timespec *sample_time, dou for (i = 0; i < n; i++) { s = &filter->samples[filter->selected[i]]; - UTI_DiffTimespecsToDouble(&filter->x_data[i], &s->sample_time, &ls->sample_time); + filter->x_data[i] = UTI_DiffTimespecsToDouble(&s->sample_time, &ls->sample_time); filter->y_data[i] = s->offset; filter->w_data[i] = s->dispersion; } diff --git a/refclock_phc.c b/refclock_phc.c index df8bf35..21ca9b5 100644 --- a/refclock_phc.c +++ b/refclock_phc.c @@ -157,7 +157,7 @@ static int phc_poll(RCL_Instance instance) /* Find the fastest reading */ for (i = 0; i < NUM_READINGS; i++) { - UTI_DiffTimespecsToDouble(&delay, &readings[i].sys_ts2, &readings[i].sys_ts1); + delay = UTI_DiffTimespecsToDouble(&readings[i].sys_ts2, &readings[i].sys_ts1); if (!i || best_delay > delay) { best = i; @@ -165,8 +165,8 @@ static int phc_poll(RCL_Instance instance) } } - UTI_DiffTimespecsToDouble(&offset, &readings[best].phc_ts, &readings[best].sys_ts2); - offset += best_delay / 2.0; + offset = UTI_DiffTimespecsToDouble(&readings[best].phc_ts, &readings[best].sys_ts2) + + best_delay / 2.0; DEBUG_LOG(LOGF_Refclock, "PHC offset: %+.9f delay: %.9f", offset, best_delay); diff --git a/refclock_shm.c b/refclock_shm.c index aa8b262..905121b 100644 --- a/refclock_shm.c +++ b/refclock_shm.c @@ -121,7 +121,7 @@ static int shm_poll(RCL_Instance instance) UTI_NormaliseTimespec(&clock_ts); UTI_NormaliseTimespec(&receive_ts); - UTI_DiffTimespecsToDouble(&offset, &clock_ts, &receive_ts); + offset = UTI_DiffTimespecsToDouble(&clock_ts, &receive_ts); return RCL_AddSample(instance, &receive_ts, offset, t.leap); } diff --git a/reference.c b/reference.c index 449e585..f5568f9 100644 --- a/reference.c +++ b/reference.c @@ -475,7 +475,7 @@ schedule_fb_drift(struct timespec *now) if (fb_drift_timeout_id) return; /* already scheduled */ - UTI_DiffTimespecsToDouble(&unsynchronised, now, &last_ref_update); + unsynchronised = UTI_DiffTimespecsToDouble(now, &last_ref_update); for (c = secs = 0, i = fb_drift_min; i <= fb_drift_max; i++) { secs = 1 << i; @@ -936,7 +936,7 @@ REF_SetReference(int stratum, LCL_GetOffsetCorrection(&raw_now, &uncorrected_offset, NULL); UTI_AddDoubleToTimespec(&raw_now, uncorrected_offset, &now); - UTI_DiffTimespecsToDouble(&elapsed, &now, ref_time); + elapsed = UTI_DiffTimespecsToDouble(&now, ref_time); our_offset = offset + elapsed * frequency; if (!is_offset_ok(our_offset)) @@ -954,7 +954,7 @@ REF_SetReference(int stratum, our_root_dispersion = root_dispersion; if (last_ref_update.tv_sec) { - UTI_DiffTimespecsToDouble(&update_interval, &now, &last_ref_update); + update_interval = UTI_DiffTimespecsToDouble(&now, &last_ref_update); if (update_interval < 0.0) update_interval = 0.0; } else { @@ -1162,7 +1162,7 @@ REF_GetReferenceParams assert(initialised); if (are_we_synchronised) { - UTI_DiffTimespecsToDouble(&elapsed, local_time, &our_ref_time); + elapsed = UTI_DiffTimespecsToDouble(local_time, &our_ref_time); dispersion = our_root_dispersion + (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed; } else { diff --git a/rtc_linux.c b/rtc_linux.c index e482d9e..8d73102 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -1040,7 +1040,7 @@ RTC_Linux_TimePreInit(time_t driftfile_time) return 0; } - UTI_DiffTimespecsToDouble(&sys_offset, &old_sys_time, &new_sys_time); + sys_offset = UTI_DiffTimespecsToDouble(&old_sys_time, &new_sys_time); /* Set system time only if the step is larger than 1 second */ if (fabs(sys_offset) >= 1.0) { diff --git a/sched.c b/sched.c index 0decfb8..d6a1eba 100644 --- a/sched.c +++ b/sched.c @@ -387,7 +387,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness, new_min_delay = min_delay; /* Check the separation from the last dispatched timeout */ - UTI_DiffTimespecsToDouble(&diff, &now, &last_class_dispatch[class]); + diff = UTI_DiffTimespecsToDouble(&now, &last_class_dispatch[class]); if (diff < separation && diff >= 0.0 && diff + new_min_delay < separation) { new_min_delay = separation - diff; } @@ -396,7 +396,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness, if necessary to keep at least the separation away */ for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) { if (ptr->class == class) { - UTI_DiffTimespecsToDouble(&diff, &ptr->ts, &now); + diff = UTI_DiffTimespecsToDouble(&ptr->ts, &now); if (new_min_delay > diff) { if (new_min_delay - diff < separation) { new_min_delay = diff + separation; @@ -410,7 +410,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness, } for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) { - UTI_DiffTimespecsToDouble(&diff, &ptr->ts, &now); + diff = UTI_DiffTimespecsToDouble(&ptr->ts, &now); if (diff > new_min_delay) { break; } @@ -665,8 +665,8 @@ check_current_time(struct timespec *prev_raw, struct timespec *raw, int timeout, return 1; } - UTI_DiffTimespecsToDouble(&step, &last_select_ts_raw, raw); - UTI_TimespecToDouble(&elapsed_min, &elapsed); + step = UTI_DiffTimespecsToDouble(&last_select_ts_raw, raw); + elapsed = UTI_TimespecToDouble(&elapsed_min); step += elapsed; /* Cooked time may no longer be valid after dispatching the handlers */ diff --git a/smooth.c b/smooth.c index 9d34be4..4fa037b 100644 --- a/smooth.c +++ b/smooth.c @@ -103,7 +103,7 @@ get_smoothing(struct timespec *now, double *poffset, double *pfreq, double elapsed, length, offset, freq, wander; int i; - UTI_DiffTimespecsToDouble(&elapsed, now, &last_update); + elapsed = UTI_DiffTimespecsToDouble(now, &last_update); offset = smooth_offset; freq = smooth_freq; @@ -327,7 +327,7 @@ SMT_GetSmoothingReport(RPT_SmoothingReport *report, struct timespec *now) report->freq_ppm *= -1.0e6; report->wander_ppm *= -1.0e6; - UTI_DiffTimespecsToDouble(&elapsed, now, &last_update); + elapsed = UTI_DiffTimespecsToDouble(now, &last_update); if (!locked && elapsed >= 0.0) { for (i = 0, length = 0.0; i < NUM_STAGES; i++) length += stages[i].length; diff --git a/sources.c b/sources.c index a02e207..d0e494a 100644 --- a/sources.c +++ b/sources.c @@ -564,7 +564,7 @@ combine_sources(int n_sel_sources, struct timespec *ref_time, double *offset, if (sources[index]->status == SRC_OK) sources[index]->status = SRC_UNSELECTED; - UTI_DiffTimespecsToDouble(&elapsed, ref_time, &src_ref_time); + elapsed = UTI_DiffTimespecsToDouble(ref_time, &src_ref_time); src_offset += elapsed * src_frequency; offset_weight = 1.0 / sources[index]->sel_info.root_distance; frequency_weight = 1.0 / src_skew; diff --git a/sourcestats.c b/sourcestats.c index e1829e6..1ecff41 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -350,8 +350,7 @@ convert_to_intervals(SST_Stats inst, double *times_back) ts = &inst->sample_times[inst->last_sample]; for (i = -inst->runs_samples; i < inst->n_samples; i++) { /* The entries in times_back[] should end up negative */ - UTI_DiffTimespecsToDouble(×_back[i], - &inst->sample_times[get_runsbuf_index(inst, i)], ts); + times_back[i] = UTI_DiffTimespecsToDouble(&inst->sample_times[get_runsbuf_index(inst, i)], ts); } } @@ -624,7 +623,7 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now, *stratum = inst->strata[get_buf_index(inst, inst->n_samples - 1)]; *variance = inst->variance; - UTI_DiffTimespecsToDouble(&sample_elapsed, now, &inst->sample_times[i]); + sample_elapsed = UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]); offset = inst->offsets[i] + sample_elapsed * inst->estimated_frequency; *root_distance = 0.5 * inst->root_delays[j] + inst->root_dispersions[j] + sample_elapsed * inst->skew; @@ -636,7 +635,7 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now, double average_offset, elapsed; int average_ok; /* average_ok ignored for now */ - UTI_DiffTimespecsToDouble(&elapsed, now, &(inst->offset_time)); + elapsed = UTI_DiffTimespecsToDouble(now, &inst->offset_time); average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed; if (fabs(average_offset - offset) <= inst->peer_dispersions[j] + 0.5 * inst->peer_delays[i]) { @@ -647,9 +646,9 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now, #endif i = get_runsbuf_index(inst, 0); - UTI_DiffTimespecsToDouble(first_sample_ago, now, &inst->sample_times[i]); + *first_sample_ago = UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]); i = get_runsbuf_index(inst, inst->n_samples - 1); - UTI_DiffTimespecsToDouble(last_sample_ago, now, &inst->sample_times[i]); + *last_sample_ago = UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]); *select_ok = inst->regression_ok; @@ -681,7 +680,7 @@ SST_GetTrackingData(SST_Stats inst, struct timespec *ref_time, *skew = inst->skew; *root_delay = inst->root_delays[j]; - UTI_DiffTimespecsToDouble(&elapsed_sample, &inst->offset_time, &inst->sample_times[i]); + elapsed_sample = UTI_DiffTimespecsToDouble(&inst->offset_time, &inst->sample_times[i]); *root_dispersion = inst->root_dispersions[j] + inst->skew * elapsed_sample; DEBUG_LOG(LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) avoff=%f offsd=%f disp=%f", @@ -757,7 +756,7 @@ SST_PredictOffset(SST_Stats inst, struct timespec *when) return 0.0; } } else { - UTI_DiffTimespecsToDouble(&elapsed, when, &inst->offset_time); + elapsed = UTI_DiffTimespecsToDouble(when, &inst->offset_time); return inst->estimated_offset + elapsed * inst->estimated_frequency; } @@ -784,7 +783,7 @@ SST_IsGoodSample(SST_Stats inst, double offset, double delay, if (inst->n_samples < 3) return 1; - UTI_DiffTimespecsToDouble(&elapsed, when, &inst->offset_time); + elapsed = UTI_DiffTimespecsToDouble(when, &inst->offset_time); /* Require that the ratio of the increase in delay from the minimum to the standard deviation is less than max_delay_dev_ratio. In the allowed @@ -953,15 +952,15 @@ SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report, struct ti if (inst->n_samples > 1) { li = get_runsbuf_index(inst, inst->n_samples - 1); lj = get_buf_index(inst, inst->n_samples - 1); - UTI_DiffTimespecsToDouble(&dspan, &inst->sample_times[li], + dspan = UTI_DiffTimespecsToDouble(&inst->sample_times[li], &inst->sample_times[get_runsbuf_index(inst, 0)]); report->span_seconds = (unsigned long) (dspan + 0.5); if (inst->n_samples > 3) { - UTI_DiffTimespecsToDouble(&elapsed, now, &inst->offset_time); + elapsed = UTI_DiffTimespecsToDouble(now, &inst->offset_time); bi = get_runsbuf_index(inst, inst->best_single_sample); bj = get_buf_index(inst, inst->best_single_sample); - UTI_DiffTimespecsToDouble(&sample_elapsed, now, &inst->sample_times[bi]); + sample_elapsed = UTI_DiffTimespecsToDouble(now, &inst->sample_times[bi]); report->est_offset = inst->estimated_offset + elapsed * inst->estimated_frequency; report->est_offset_err = (inst->estimated_offset_sd + sample_elapsed * inst->skew + diff --git a/sys_generic.c b/sys_generic.c index 1bb16f8..90eaa0c 100644 --- a/sys_generic.c +++ b/sys_generic.c @@ -178,7 +178,7 @@ update_slew(void) LCL_ReadRawTime(&now); /* Adjust the offset register by achieved slew */ - UTI_DiffTimespecsToDouble(&duration, &now, &slew_start); + duration = UTI_DiffTimespecsToDouble(&now, &slew_start); offset_register -= slew_freq * duration; stop_fastslew(&now); @@ -299,7 +299,7 @@ offset_convert(struct timespec *raw, { double duration, fastslew_corr, fastslew_err; - UTI_DiffTimespecsToDouble(&duration, raw, &slew_start); + duration = UTI_DiffTimespecsToDouble(raw, &slew_start); if (drv_get_offset_correction && fastslew_active) { drv_get_offset_correction(raw, &fastslew_corr, &fastslew_err); @@ -338,7 +338,7 @@ apply_step_offset(double offset) } LCL_ReadRawTime(&old_time); - UTI_DiffTimespecsToDouble(&err, &old_time, &new_time); + err = UTI_DiffTimespecsToDouble(&old_time, &new_time); lcl_InvokeDispersionNotifyHandlers(fabs(err)); diff --git a/sys_macosx.c b/sys_macosx.c index 9a071dd..35f03d6 100644 --- a/sys_macosx.c +++ b/sys_macosx.c @@ -143,10 +143,10 @@ start_adjust(void) /* Determine the amount of error built up since the last adjustment */ LCL_ReadRawTime(&T1); - UTI_DiffTimespecsToDouble(&elapsed, &T1, &T0); + elapsed = UTI_DiffTimespecsToDouble(&T1, &T0); accrued_error = elapsed * current_freq; - UTI_DiffTimespecsToDouble(&drift_removal_elapsed, &T1, &Tdrift); + drift_removal_elapsed = UTI_DiffTimespecsToDouble(&T1, &Tdrift); /* To allow for the clock being stepped either forward or backwards, clamp the elapsed time to bounds [ 0.0, current_drift_removal_interval ] */ @@ -162,14 +162,14 @@ start_adjust(void) adjust_required = - (accrued_error + offset_register + predicted_error); UTI_DoubleToTimeval(adjust_required, &newadj); - UTI_TimevalToDouble(&newadj, &adjustment_requested); + adjustment_requested = UTI_TimevalToDouble(&newadj); rounding_error = adjust_required - adjustment_requested; if (PRV_AdjustTime(&newadj, &oldadj) < 0) { LOG_FATAL(LOGF_SysMacOSX, "adjtime() failed"); } - UTI_TimevalToDouble(&oldadj, &old_adjust_remaining); + old_adjust_remaining = UTI_TimevalToDouble(&oldadj); offset_register = rounding_error - old_adjust_remaining - predicted_error; @@ -195,8 +195,8 @@ stop_adjust(void) LCL_ReadRawTime(&T1); - UTI_DiffTimespecsToDouble(&elapsed, &T1, &T0); - UTI_TimevalToDouble(&remadj, &adjustment_remaining); + elapsed = UTI_DiffTimespecsToDouble(&T1, &T0); + adjustment_remaining = UTI_TimevalToDouble(&remadj); adjustment_achieved = adjustment_requested - adjustment_remaining; elapsed_plus_adjust = elapsed - adjustment_achieved; @@ -333,7 +333,7 @@ set_sync_status(int synchronised, double est_error, double max_error) double rtc_sync_elapsed; SCH_GetLastEventTime(NULL, NULL, &now); - UTI_DiffTimespecsToDouble(&rtc_sync_elapsed, &now, &last_rtc_sync); + rtc_sync_elapsed = UTI_DiffTimespecsToDouble(&now, &last_rtc_sync); if (fabs(rtc_sync_elapsed) >= RTC_SYNC_INTERVAL) { /* update the RTC by applying a step of 0.0 secs */ apply_step_offset(0.0); diff --git a/sys_netbsd.c b/sys_netbsd.c index 509add5..74cadbc 100644 --- a/sys_netbsd.c +++ b/sys_netbsd.c @@ -68,7 +68,7 @@ accrue_offset(double offset, double corr_rate) LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); /* Add the old remaining adjustment if not zero */ - UTI_TimevalToDouble(&oldadj, &doldadj); + doldadj = UTI_TimevalToDouble(&oldadj); if (doldadj != 0.0) { UTI_DoubleToTimeval(-offset + doldadj, &newadj); if (PRV_AdjustTime(&newadj, NULL) < 0) @@ -88,7 +88,7 @@ get_offset_correction(struct timespec *raw, if (PRV_AdjustTime(NULL, &remadj) < 0) LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); - UTI_TimevalToDouble(&remadj, &adjustment_remaining); + adjustment_remaining = UTI_TimevalToDouble(&remadj); *corr = adjustment_remaining; if (err) { diff --git a/util.c b/util.c index 18a5167..fa9ee2a 100644 --- a/util.c +++ b/util.c @@ -65,10 +65,10 @@ UTI_TimespecToTimeval(struct timespec *ts, struct timeval *tv) /* ================================================== */ -void -UTI_TimespecToDouble(struct timespec *ts, double *d) +double +UTI_TimespecToDouble(struct timespec *ts) { - *d = ts->tv_sec + 1.0e-9 * ts->tv_nsec; + return ts->tv_sec + 1.0e-9 * ts->tv_nsec; } /* ================================================== */ @@ -100,11 +100,10 @@ UTI_NormaliseTimespec(struct timespec *ts) /* ================================================== */ -void -UTI_TimevalToDouble(struct timeval *a, double *b) +double +UTI_TimevalToDouble(struct timeval *tv) { - *b = (double)(a->tv_sec) + 1.0e-6 * (double)(a->tv_usec); - + return tv->tv_sec + 1.0e-6 * tv->tv_usec; } /* ================================================== */ @@ -170,10 +169,10 @@ UTI_DiffTimespecs(struct timespec *result, struct timespec *a, struct timespec * /* ================================================== */ /* Calculate result = a - b and return as a double */ -void -UTI_DiffTimespecsToDouble(double *result, struct timespec *a, struct timespec *b) +double +UTI_DiffTimespecsToDouble(struct timespec *a, struct timespec *b) { - *result = (a->tv_sec - b->tv_sec) + 1.0e-9 * (a->tv_nsec - b->tv_nsec); + return (a->tv_sec - b->tv_sec) + 1.0e-9 * (a->tv_nsec - b->tv_nsec); } /* ================================================== */ @@ -196,7 +195,7 @@ void UTI_AverageDiffTimespecs(struct timespec *earlier, struct timespec *later, struct timespec *average, double *diff) { - UTI_DiffTimespecsToDouble(diff, later, earlier); + *diff = UTI_DiffTimespecsToDouble(later, earlier); UTI_AddDoubleToTimespec(earlier, *diff / 2.0, average); } @@ -208,7 +207,7 @@ UTI_AddDiffToTimespec(struct timespec *a, struct timespec *b, { double diff; - UTI_DiffTimespecsToDouble(&diff, a, b); + diff = UTI_DiffTimespecsToDouble(a, b); UTI_AddDoubleToTimespec(c, diff, result); } @@ -609,7 +608,7 @@ UTI_AdjustTimespec(struct timespec *old_ts, struct timespec *when, struct timesp { double elapsed; - UTI_DiffTimespecsToDouble(&elapsed, when, old_ts); + elapsed = UTI_DiffTimespecsToDouble(when, old_ts); *delta_time = elapsed * dfreq - doffset; UTI_AddDoubleToTimespec(old_ts, *delta_time, new_ts); } @@ -742,8 +741,7 @@ UTI_IsTimeOffsetSane(struct timespec *ts, double offset) if (!(offset > -MAX_OFFSET && offset < MAX_OFFSET)) return 0; - UTI_TimespecToDouble(ts, &t); - t += offset; + t = UTI_TimespecToDouble(ts) + offset; /* Time before 1970 is not considered valid */ if (t < 0.0) diff --git a/util.h b/util.h index 01a297c..72d520d 100644 --- a/util.h +++ b/util.h @@ -44,7 +44,7 @@ extern void UTI_TimevalToTimespec(struct timeval *tv, struct timespec *ts); extern void UTI_TimespecToTimeval(struct timespec *ts, struct timeval *tv); /* Convert a timespec into a floating point number of seconds */ -extern void UTI_TimespecToDouble(struct timespec *ts, double *d); +extern double UTI_TimespecToDouble(struct timespec *ts); /* Convert a number of seconds expressed in floating point into a timespec */ @@ -55,7 +55,7 @@ extern void UTI_DoubleToTimespec(double d, struct timespec *ts); extern void UTI_NormaliseTimespec(struct timespec *ts); /* Convert a timeval into a floating point number of seconds */ -extern void UTI_TimevalToDouble(struct timeval *a, double *b); +extern double UTI_TimevalToDouble(struct timeval *tv); /* Convert a number of seconds expressed in floating point into a timeval */ @@ -73,7 +73,7 @@ extern int UTI_CompareTimespecs(struct timespec *a, struct timespec *b); extern void UTI_DiffTimespecs(struct timespec *result, struct timespec *a, struct timespec *b); /* Calculate result = a - b and return as a double */ -extern void UTI_DiffTimespecsToDouble(double *result, struct timespec *a, struct timespec *b); +extern double UTI_DiffTimespecsToDouble(struct timespec *a, struct timespec *b); /* Add a double increment to a timespec to get a new one. 'start' is the starting time, 'end' is the result that we return. This is