Ensure alarms are called back when they expire in the past
Turns out the posix timers we're dealing with aren't well behaved. If the timer is TIMER_ABSTIME the following is supposed to be true: "If the specified time has already passed, the function shall succeed and the expiration notification shall be made." But alas, this is not the case. If the expiration time happens to be in the past (e.g. very short timer which gets hit with a context switch before the timer can be set) the timer decides to disarm itself. This means no more callbacks happen, and no more alarms are processed ever. sadness. But thankfully, we can use timer_gettime to check the state of the timer after timer_settime. If timer_gettime tells us the timer is disarmed right after we armed it, we want to perform the alarm callback ourselves. Put all timer callbacks on the same thread (as would be the case in the underlying timer implementation already) and used a sempahore to signal when an alarm expires in the normal posix timer callback and also in the timer didn't set case. Change-Id: I39854b241369b2da52afbaaba0c01d3167a47e32
Loading
Please register or sign in to comment