mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
timeout: replace Duration operators by methods
void += (Microseconds) -> void add(Microseconds) void += (Milliseconds) -> void add(Milliseconds) bool < (Duration) -> bool less_than(Duration) Issue #2581
This commit is contained in:
parent
26bcd439f7
commit
e87f63944f
@ -332,8 +332,8 @@ _ZN6Genode7cap_mapEv T
|
||||
_ZN6Genode7vprintfEPKcP13__va_list_tag T
|
||||
_ZN6Genode7vprintfEPKcPc T
|
||||
_ZN6Genode7vprintfEPKcSt9__va_list T
|
||||
_ZN6Genode8DurationpLENS_12MicrosecondsE T
|
||||
_ZN6Genode8DurationpLENS_12MillisecondsE T
|
||||
_ZN6Genode8Duration3addENS_12MicrosecondsE T
|
||||
_ZN6Genode8Duration3addENS_12MillisecondsE T
|
||||
_ZN6Genode8ipc_callENS_17Native_capabilityERNS_11Msgbuf_baseES2_m T
|
||||
_ZN6Genode9ipc_replyENS_17Native_capabilityENS_18Rpc_exception_codeERNS_11Msgbuf_baseE T
|
||||
_ZN9Component10stack_sizeEv T
|
||||
@ -360,7 +360,7 @@ _ZNK6Genode6Thread10stack_baseEv T
|
||||
_ZNK6Genode6Thread4nameEv T
|
||||
_ZNK6Genode6Thread9stack_topEv T
|
||||
_ZNK6Genode8Duration17trunc_to_plain_usEv T
|
||||
_ZNK6Genode8DurationltERS0_ T
|
||||
_ZNK6Genode8Duration9less_thanERS0_ T
|
||||
_ZNKSt13bad_exception4whatEv T
|
||||
_ZNKSt9exception4whatEv T
|
||||
_ZNSt13bad_exceptionD0Ev T
|
||||
|
@ -71,13 +71,13 @@ struct Genode::Duration
|
||||
|
||||
public:
|
||||
|
||||
void operator += (Microseconds us);
|
||||
void operator += (Milliseconds ms);
|
||||
void add(Microseconds us);
|
||||
void add(Milliseconds ms);
|
||||
|
||||
bool operator < (Duration &other) const;
|
||||
bool less_than(Duration &other) const;
|
||||
|
||||
explicit Duration(Milliseconds ms) { *this += ms; }
|
||||
explicit Duration(Microseconds us) { *this += us; }
|
||||
explicit Duration(Milliseconds ms) { add(ms); }
|
||||
explicit Duration(Microseconds us) { add(us); }
|
||||
|
||||
Microseconds trunc_to_plain_us() const;
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ Duration Timer::Time_source::curr_time()
|
||||
if (timeout_age_us > _last_timeout_age_us) {
|
||||
|
||||
/* increment time by the difference since the last update */
|
||||
_curr_time += Microseconds(timeout_age_us - _last_timeout_age_us);
|
||||
_curr_time.add(Microseconds(timeout_age_us - _last_timeout_age_us));
|
||||
_last_timeout_age_us = timeout_age_us;
|
||||
}
|
||||
return _curr_time;
|
||||
|
@ -77,8 +77,8 @@ class Timer::Time_source : public Threaded_time_source
|
||||
|
||||
/* update in irq context or if update rate is below 4000 irq/s */
|
||||
if (_irq || diff.value > 250) {
|
||||
_curr_time += diff;
|
||||
_tsc_last = curr_tsc;
|
||||
_curr_time.add(diff);
|
||||
_tsc_last = curr_tsc;
|
||||
}
|
||||
|
||||
return _curr_time;
|
||||
|
@ -40,7 +40,7 @@ void Duration::_add_us_less_than_an_hour(unsigned long us)
|
||||
}
|
||||
|
||||
|
||||
void Duration::operator += (Microseconds us)
|
||||
void Duration::add(Microseconds us)
|
||||
{
|
||||
/* filter out hours if any */
|
||||
if (us.value >= (unsigned long)US_PER_HOUR) {
|
||||
@ -53,7 +53,7 @@ void Duration::operator += (Microseconds us)
|
||||
}
|
||||
|
||||
|
||||
void Duration::operator += (Milliseconds ms)
|
||||
void Duration::add(Milliseconds ms)
|
||||
{
|
||||
/* filter out hours if any */
|
||||
if (ms.value >= MS_PER_HOUR) {
|
||||
@ -66,7 +66,7 @@ void Duration::operator += (Milliseconds ms)
|
||||
}
|
||||
|
||||
|
||||
bool Duration::operator < (Duration &other) const
|
||||
bool Duration::less_than(Duration &other) const
|
||||
{
|
||||
if (_hours != other._hours) {
|
||||
return _hours < other._hours; }
|
||||
|
@ -78,7 +78,7 @@ Duration Timer::Connection::_update_interpolated_time(Duration &interpolated_tim
|
||||
* jump back but to freeze at the higher value until the new
|
||||
* interpolation has caught up.
|
||||
*/
|
||||
if (_interpolated_time < interpolated_time) {
|
||||
if (_interpolated_time.less_than(interpolated_time)) {
|
||||
_interpolated_time = interpolated_time; }
|
||||
|
||||
return _interpolated_time;
|
||||
|
@ -79,9 +79,9 @@ void Timer::Connection::_update_real_time()
|
||||
Timestamp ts_diff = ts - _ts;
|
||||
|
||||
/* overwrite timestamp, time, and real time member */
|
||||
_us = us;
|
||||
_ts = ts;
|
||||
_real_time += Microseconds(us_diff);
|
||||
_us = us;
|
||||
_ts = ts;
|
||||
_real_time.add(Microseconds(us_diff));
|
||||
|
||||
|
||||
/*
|
||||
@ -198,12 +198,12 @@ Duration Timer::Connection::curr_time()
|
||||
unsigned long const us_diff = _ts_to_us_ratio(ts_diff, us_to_ts_factor,
|
||||
us_to_ts_factor_shift);
|
||||
|
||||
interpolated_time += Microseconds(us_diff);
|
||||
interpolated_time.add(Microseconds(us_diff));
|
||||
|
||||
} else {
|
||||
|
||||
/* use remote timer instead of timestamps */
|
||||
interpolated_time += Microseconds(elapsed_us() - _us);
|
||||
interpolated_time.add(Microseconds(elapsed_us() - _us));
|
||||
|
||||
lock_guard.destruct();
|
||||
}
|
||||
|
@ -121,48 +121,48 @@ struct Duration_test : Test
|
||||
Duration max_minus_1 (Microseconds(~0UL - 1));
|
||||
|
||||
/* all must be greater than the minimum */
|
||||
if (min_plus_1 < min) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_minus_1 < min) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour < min) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_plus_1 < min) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < min) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max_minus_1 < min) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (min_plus_1 .less_than(min)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_minus_1.less_than(min)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour .less_than(min)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_plus_1 .less_than(min)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max .less_than(min)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max_minus_1 .less_than(min)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
|
||||
/* all must be less than the maximum */
|
||||
if (max < min ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < min_plus_1 ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < hour_minus_1) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < hour ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < hour_plus_1 ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < max_minus_1 ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max.less_than(min )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max.less_than(min_plus_1 )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max.less_than(hour_minus_1)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max.less_than(hour )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max.less_than(hour_plus_1 )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max.less_than(max_minus_1 )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
|
||||
/* consistency around one hour */
|
||||
if (hour < hour_minus_1) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_plus_1 < hour ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour .less_than(hour_minus_1)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_plus_1.less_than(hour )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
}
|
||||
/* consistency when we double the values */
|
||||
Duration two_hours = hour;
|
||||
Duration two_max = max;
|
||||
two_hours += Microseconds((unsigned long)US_PER_HOUR);
|
||||
two_max += Microseconds(~0UL);
|
||||
if (two_hours < hour) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (two_max < max) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
two_hours.add(Microseconds((unsigned long)US_PER_HOUR));
|
||||
two_max .add(Microseconds(~0UL));
|
||||
if (two_hours.less_than(hour)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (two_max .less_than(max )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
|
||||
/* create durations near corner cases by increasing after construction */
|
||||
Duration hour_minus_1(Microseconds((unsigned long)US_PER_HOUR - 2));
|
||||
Duration hour_plus_1 (Microseconds((unsigned long)US_PER_HOUR));
|
||||
Duration max_minus_1 (Microseconds(~0UL - 2));
|
||||
Duration max_plus_1 (Microseconds(~0UL));
|
||||
hour_minus_1 += Microseconds(1);
|
||||
hour_plus_1 += Microseconds(1);
|
||||
max_minus_1 += Microseconds(1);
|
||||
max_plus_1 += Microseconds(1);
|
||||
hour_minus_1.add(Microseconds(1));
|
||||
hour_plus_1 .add(Microseconds(1));
|
||||
max_minus_1 .add(Microseconds(1));
|
||||
max_plus_1 .add(Microseconds(1));
|
||||
|
||||
/* consistency around corner cases */
|
||||
if (hour < hour_minus_1) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_plus_1 < hour ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max < max_minus_1 ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max_plus_1 < max ) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour .less_than(hour_minus_1)) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (hour_plus_1.less_than(hour )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max .less_than(max_minus_1 )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (max_plus_1 .less_than(max )) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
|
||||
log("tests near maximum duration value (may take a while)");
|
||||
|
||||
@ -200,9 +200,9 @@ struct Duration_test : Test
|
||||
while (1) {
|
||||
for (; duration_id < NR; duration_id++) {
|
||||
|
||||
if (nr_left > 4) { duration[duration_id] += Milliseconds(~0UL / (step + 1)); }
|
||||
else if (nr_left == 4) { duration[duration_id] += Milliseconds(1000UL); }
|
||||
else if (nr_left < 4) { duration[duration_id] += Microseconds(1UL); }
|
||||
if (nr_left > 4) { duration[duration_id].add(Milliseconds(~0UL / (step + 1))); }
|
||||
else if (nr_left == 4) { duration[duration_id].add(Milliseconds(1000UL)); }
|
||||
else if (nr_left < 4) { duration[duration_id].add(Microseconds(1UL)); }
|
||||
}
|
||||
duration_id = step;
|
||||
}
|
||||
@ -217,18 +217,18 @@ struct Duration_test : Test
|
||||
* than the maximum possible duration value. So, test consistency at
|
||||
* this corner case.
|
||||
*/
|
||||
duration[NR - 2] += Microseconds(1);
|
||||
if (duration[NR - 2] < duration[NR - 1]) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (duration[NR - 1] < duration[NR - 2]) ; else { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
duration[NR - 2].add(Microseconds(1));
|
||||
if (duration[NR - 2].less_than(duration[NR - 1])) { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
if (duration[NR - 1].less_than(duration[NR - 2])) ; else { error(__func__, ":", __LINE__); error_cnt++; }
|
||||
|
||||
/* test if we really had the expected durations */
|
||||
try {
|
||||
duration[NR - 2] += Microseconds(1);
|
||||
duration[NR - 2].add(Microseconds(1));
|
||||
error(__func__, ":", __LINE__); error_cnt++;
|
||||
}
|
||||
catch (Duration::Overflow) { }
|
||||
try {
|
||||
duration[NR - 1] += Microseconds(2);
|
||||
duration[NR - 1].add(Microseconds(2));
|
||||
error(__func__, ":", __LINE__); error_cnt++;
|
||||
}
|
||||
catch (Duration::Overflow) { }
|
||||
|
Loading…
Reference in New Issue
Block a user