poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] pvm: Refactor sleep to push erorrs and to check ranges


From: Jose E. Marchesi
Subject: Re: [PATCH] pvm: Refactor sleep to push erorrs and to check ranges
Date: Mon, 23 Jan 2023 15:01:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Arsen.

Thanks for the patch.
There is a small typo on the patch title: s/erorrs/errors.

I see there are already tests in place that check for this (sleep-*.pk).
Other than the type above, LGTM.
OK for master.

> +/* Sleep instruction wrapper.  */
> +
> +immutable fun sleep = (int<64> sec, int<64> nsec = 0) void:
> +{
> +  var err = 0;
> +  asm ("sleep; nip2" : err : sec, nsec);
> +  if (err == -1)
> +    raise E_inval;
> +  if (err == -2)
> +    raise E_generic;
> +  assert (err == 0,
> +          "Unhandled error in sleep()!  Please email <poke-devel@gnu.org>.");
> +}
>
>  /* The following function implements the fast path of the aoref macro
>     in pkl-gen.pks.  Given an array whose elements have all the same
>     size, which is known at compile-time, and an offset, return the
> diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
> index 8f7f33aa..6070b59b 100644
> --- a/libpoke/pvm.jitter
> +++ b/libpoke/pvm.jitter
> @@ -6843,32 +6843,33 @@ end
>  # Sleep for a given number of seconds and nanoseconds.
>  #
>  # If the provided number of nanoseconds are not in the range 0 to
> -# 999999999 or the number of provided seconds is negative, raise
> -# PVM_E_INVAL.
> +# 999999999 or the number of provided seconds is negative, pushes
> +# -1.
>  #
> -# If there is any other error performing the operation then raise
> -# PVM_E_GENERIC.
> +# If there is any other error performing the operation then push
> +# -2.
>  #
> -# Stack: ( LONG LONG -- LONG LONG )
> -# Exceptions: PVM_E_INVAL, PVM_E_GENERIC
> +# EINTR is treated as no error currently.
> +#
> +# Stack: ( LONG LONG -- LONG LONG INT )
>  
>  instruction sleep ()
> -  branching # because of PVM_RAISE_DIRECT
>    code
>      struct timespec ts;
>  
>      ts.tv_sec = PVM_VAL_LONG (JITTER_UNDER_TOP_STACK ());
>      ts.tv_nsec = PVM_VAL_LONG (JITTER_TOP_STACK ());
>  
> -    if (pvm_nanosleep (&ts, NULL) == -1)
> +    if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec > 999999999)
> +      JITTER_PUSH_STACK (PVM_MAKE_INT (-1, 32));
> +    else if (pvm_nanosleep (&ts, NULL) == -1 && errno != EINTR)
>      {
> -      if (errno == EINTR)
> -        /* This is most likely Ctrl-C.  Do nothing */;
> -      else if (errno == EINVAL)
> -        PVM_RAISE_DFL (PVM_E_INVAL);
> +      if (errno == EINVAL)
> +        JITTER_PUSH_STACK (PVM_MAKE_INT (-1, 32));
>        else
> -        PVM_RAISE_DFL (PVM_E_GENERIC);
> -    }
> +        JITTER_PUSH_STACK (PVM_MAKE_INT (-2, 32));
> +    } else
> +      JITTER_PUSH_STACK (PVM_MAKE_INT (0, 32));
>    end
>  end



reply via email to

[Prev in Thread] Current Thread [Next in Thread]