mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 11:55:24 +00:00
parent
10ec9806d3
commit
ee0566dcb1
@ -35,7 +35,7 @@ class Platform_timer
|
||||
Kernel::capid_t const _sigid;
|
||||
unsigned long mutable _curr_time_us;
|
||||
Genode::Lock mutable _curr_time_us_lock;
|
||||
unsigned long mutable _last_timeout_us;
|
||||
unsigned long mutable _last_timeout_age_us;
|
||||
time_t const _max_timeout_us;
|
||||
|
||||
/**
|
||||
@ -55,7 +55,7 @@ class Platform_timer
|
||||
Platform_timer()
|
||||
:
|
||||
_sigid(_capid(_sigrec.manage(&_sigctx))),
|
||||
_curr_time_us(0), _last_timeout_us(0),
|
||||
_curr_time_us(0), _last_timeout_age_us(0),
|
||||
_max_timeout_us(Kernel::timeout_max_us())
|
||||
{
|
||||
Genode::log("maximum timeout ", _max_timeout_us, " us");
|
||||
@ -68,7 +68,7 @@ class Platform_timer
|
||||
~Platform_timer() { _sigrec.dissolve(&_sigctx); }
|
||||
|
||||
/**
|
||||
* Refresh and return our instance-own "now"-time in microseconds
|
||||
* Refresh and return time in microseconds
|
||||
*
|
||||
* This function has to be executed regulary, at least all
|
||||
* max_timeout() us.
|
||||
@ -76,9 +76,13 @@ class Platform_timer
|
||||
unsigned long curr_time() const
|
||||
{
|
||||
Genode::Lock::Guard lock(_curr_time_us_lock);
|
||||
time_t const passed_us = Kernel::timeout_age_us();
|
||||
_last_timeout_us -= passed_us;
|
||||
_curr_time_us += passed_us;
|
||||
time_t const timeout_age_us = Kernel::timeout_age_us();
|
||||
if (timeout_age_us > _last_timeout_age_us) {
|
||||
|
||||
/* increment time by the difference since the last update */
|
||||
_curr_time_us += timeout_age_us - _last_timeout_age_us;
|
||||
_last_timeout_age_us = timeout_age_us;
|
||||
}
|
||||
return _curr_time_us;
|
||||
}
|
||||
|
||||
@ -108,7 +112,7 @@ class Platform_timer
|
||||
* timeout counter through 'curr_time()' (We rely on the fact that
|
||||
* this is done at least one time in every max-timeout period)
|
||||
*/
|
||||
_last_timeout_us = timeout_us;
|
||||
_last_timeout_age_us = 0;
|
||||
Kernel::timeout(timeout_us, _sigid);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user