setitimer, small delta and XNU

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

setitimer, small delta and XNU

Holger Freyther
Dear Paolo,

I am currently switching my development environment from GNU/Linux to
XNU (OSX) and there appears a funny “scheduling” or time issue that leads
to a race-condition.


(Delay forMilliseconds: 500) wait

Can get stuck forever (e.g. the process.st testcase fails because of that). From
what I see this is happening.

_gst_sigalrm_at is getting called with a nsTime that is really close to the now
time (either because of scheduling or non linear time? I don’t know) but here
is what happens:

nsTime is 1429097745443176000
now is      1429097745442951000

this means deltaMilli will be 0 which leads to us “canceling” the timer instead
of setting it. My workaround is to make sure that tv_usec is never zero. Is this
acceptable? E.g. something like this?

diff --git a/libgst/sysdep/posix/timer.c b/libgst/sysdep/posix/timer.c
index c47ae91..10e0e92 100644
--- a/libgst/sysdep/posix/timer.c
+++ b/libgst/sysdep/posix/timer.c
@@ -121,8 +121,16 @@ _gst_sigalrm_at (int64_t nsTime)
      struct itimerval value;

      value.it_interval.tv_sec = value.it_interval.tv_usec = 0;
-      value.it_value.tv_sec = deltaMilli / 1000;
-      value.it_value.tv_usec = (deltaMilli % 1000) * 1000;
+      if (deltaMilli)
+        {
+          value.it_value.tv_sec = deltaMilli / 1000;
+          value.it_value.tv_usec = (deltaMilli % 1000) * 1000;
+        }
+      else
+        {
+          value.it_value.tv_sec = 0;
+          value.it_value.tv_usec = 1;
+        }
      setitimer (ITIMER_REAL, &value, (struct itimerval *) 0);
    }
}



_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: setitimer, small delta and XNU

Paolo Bonzini-2


On 15/04/2015 22:25, Holger Freyther wrote:

> this means deltaMilli will be 0 which leads to us “canceling” the timer instead
> of setting it. My workaround is to make sure that tv_usec is never zero. Is this
> acceptable? E.g. something like this?
>
> diff --git a/libgst/sysdep/posix/timer.c b/libgst/sysdep/posix/timer.c
> index c47ae91..10e0e92 100644
> --- a/libgst/sysdep/posix/timer.c
> +++ b/libgst/sysdep/posix/timer.c
> @@ -121,8 +121,16 @@ _gst_sigalrm_at (int64_t nsTime)
>       struct itimerval value;
>
>       value.it_interval.tv_sec = value.it_interval.tv_usec = 0;
> -      value.it_value.tv_sec = deltaMilli / 1000;
> -      value.it_value.tv_usec = (deltaMilli % 1000) * 1000;
> +      if (deltaMilli)
> +        {
> +          value.it_value.tv_sec = deltaMilli / 1000;
> +          value.it_value.tv_usec = (deltaMilli % 1000) * 1000;
> +        }
> +      else
> +        {
> +          value.it_value.tv_sec = 0;
> +          value.it_value.tv_usec = 1;
> +        }
>       setitimer (ITIMER_REAL, &value, (struct itimerval *) 0);
>     }
> }
>
>

Yes, certainly!

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk