Implement print and min/max for Microseconds and Milliseconds

Ref #3050
This commit is contained in:
Ehmry - 2018-11-18 15:23:11 +01:00 committed by Norman Feske
parent 8f43a1303b
commit 9c7d5b2a66
3 changed files with 35 additions and 3 deletions

View File

@ -360,7 +360,7 @@ _ZNK6Genode6Thread4nameEv T
_ZNK6Genode6Thread9stack_topEv T
_ZNK6Genode8Duration17trunc_to_plain_msEv T
_ZNK6Genode8Duration17trunc_to_plain_usEv T
_ZNK6Genode8Duration9less_thanERS0_ T
_ZNK6Genode8Duration9less_thanERKS0_ T
_ZNKSt13bad_exception4whatEv T
_ZNKSt9exception4whatEv T
_ZNSt13bad_exceptionD0Ev T

View File

@ -17,6 +17,7 @@
/* Genode includes */
#include <base/stdint.h>
#include <base/exception.h>
#include <base/output.h>
namespace Genode {
@ -34,6 +35,12 @@ struct Genode::Microseconds
unsigned long value;
explicit Microseconds(unsigned long value) : value(value) { }
void print(Output &out) const
{
Genode::print(out, value);
out.out_string(" us");
}
};
@ -45,6 +52,12 @@ struct Genode::Milliseconds
unsigned long value;
explicit Milliseconds(unsigned long value) : value(value) { }
void print(Output &out) const
{
Genode::print(out, value);
out.out_string(" ms");
}
};
@ -74,7 +87,7 @@ struct Genode::Duration
void add(Microseconds us);
void add(Milliseconds ms);
bool less_than(Duration &other) const;
bool less_than(Duration const &other) const;
explicit Duration(Milliseconds ms) { add(ms); }
explicit Duration(Microseconds us) { add(us); }
@ -83,4 +96,23 @@ struct Genode::Duration
Milliseconds trunc_to_plain_ms() const;
};
namespace Genode
{
static inline
Microseconds min(Microseconds const x, Microseconds const y) {
return (x.value < y.value) ? x : y; }
static inline
Microseconds max(Microseconds const x, Microseconds const y) {
return (x.value > y.value) ? x : y; }
static inline
Milliseconds min(Milliseconds const x, Milliseconds const y) {
return (x.value < y.value) ? x : y; }
static inline
Milliseconds max(Milliseconds const x, Milliseconds const y) {
return (x.value > y.value) ? x : y; }
};
#endif /* _OS__DURATION_H_ */

View File

@ -66,7 +66,7 @@ void Duration::add(Milliseconds ms)
}
bool Duration::less_than(Duration &other) const
bool Duration::less_than(Duration const &other) const
{
if (_hours != other._hours) {
return _hours < other._hours; }