On 06/15/2012 10:10 PM, Roland Stigge wrote:
> 
> Hi,
> 
> The nanosleep_test.c code shows a malfunction of the nanosleep function
> when a timer periodically triggering a signal.
> When nanosleep is interrupted the variable holding the rest of the time
> to sleep is immediately zero.
> 
> 
> 
> However, no bug is reported without the xenomai's posix skin.

The following patch should fix the bug:
diff --git a/ksrc/skins/posix/clock.c b/ksrc/skins/posix/clock.c
index 024260d..107ebb0 100644
--- a/ksrc/skins/posix/clock.c
+++ b/ksrc/skins/posix/clock.c
@@ -336,15 +336,12 @@ int clock_nanosleep(clockid_t clock_id,
        if (xnthread_test_info(cur, XNBREAK)) {

                if (flags == 0 && rmtp) {
-                       xnticks_t now, expiry;
                        xnsticks_t rem;

-                       now = clock_get_ticks(clock_id);
-                       expiry = xntimer_get_date(&cur->rtimer);
+                       rem = xntimer_get_timeout_stopped(&cur->rtimer);
                        xnlock_put_irqrestore(&nklock, s);
-                       rem = expiry - now;

-                       ticks2ts(rmtp, rem > 0 ? rem : 0);
+                       ticks2ts(rmtp, rem > 1 ? rem : 0);
                } else
                        xnlock_put_irqrestore(&nklock, s);

Note however that with xenomai, a signal received during nanosleep will
trigger a switch to secondary mode. So, this usage is only possible for
a real-time thread in exceptional conditions (to handle an error for
instance), not when latency matters.

-- 
                                                                Gilles.



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to