perf_timer: rewrite to make it clear there is no division by zero

It could have happened if epee::misc_utils::get_ns_count
is buggy, at a push

Coverity 182561
This commit is contained in:
moneromooo-monero 2018-02-02 16:05:06 +00:00
parent c6ea3df0ae
commit f3f7da624d
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
1 changed files with 3 additions and 4 deletions

View File

@ -49,16 +49,15 @@ namespace
#ifdef __x86_64__
uint64_t get_ticks_per_ns()
{
uint64_t t0 = epee::misc_utils::get_ns_count();
uint64_t t0 = epee::misc_utils::get_ns_count(), t1;
uint64_t r0 = get_tick_count();
while (1)
{
uint64_t t = epee::misc_utils::get_ns_count();
if (t - t0 > 1*1000000000) break; // work one second
t1 = epee::misc_utils::get_ns_count();
if (t1 - t0 > 1*1000000000) break; // work one second
}
uint64_t t1 = epee::misc_utils::get_ns_count();
uint64_t r1 = get_tick_count();
uint64_t tpns256 = 256 * (r1 - r0) / (t1 - t0);
return tpns256 ? tpns256 : 1;