Am 20.10.2014 um 14:37 schrieb David Heidelberger:
> From: Christoph Bumiller <christoph.bumil...@speed.at>
> 
> They're useful for Gallium Nine.
> 
> Signed-off-by: David Heidelberger <david.heidelber...@ixit.cz>
> ---
>  src/gallium/auxiliary/util/u_atomic.h | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/src/gallium/auxiliary/util/u_atomic.h 
> b/src/gallium/auxiliary/util/u_atomic.h
> index 951a01a..6271736 100644
> --- a/src/gallium/auxiliary/util/u_atomic.h
> +++ b/src/gallium/auxiliary/util/u_atomic.h
> @@ -157,6 +157,12 @@ p_atomic_inc(int32_t *v)
>     (void) __sync_add_and_fetch(v, 1);
>  }
>  
> +static INLINE int32_t
> +p_atomic_inc_return(int32_t *v)
> +{
> +   return __sync_add_and_fetch(v, 1);
> +}
> +
>  static INLINE void
>  p_atomic_dec(int32_t *v)
>  {
> @@ -164,6 +170,12 @@ p_atomic_dec(int32_t *v)
>  }
>  
>  static INLINE int32_t
> +p_atomic_dec_return(int32_t *v)
> +{
> +   return __sync_sub_and_fetch(v, 1);
> +}
> +
> +static INLINE int32_t
>  p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
>  {
>     return __sync_val_compare_and_swap(v, old, _new);
> @@ -189,6 +201,8 @@ p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
>  #define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))
>  #define p_atomic_inc(_v) ((void) (*(_v))++)
>  #define p_atomic_dec(_v) ((void) (*(_v))--)
> +#define p_atomic_inc_return(_v) ((*(_v))++)
> +#define p_atomic_dec_return(_v) ((*(_v))--)
>  #define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : 
> *(_v))
>  
>  #endif
> @@ -291,6 +305,12 @@ p_atomic_inc(int32_t *v)
>     _InterlockedIncrement((long *)v);
>  }
>  
> +static INLINE int32_t
> +p_atomic_inc_return(int32_t *v)
> +{
> +   return _InterlockedIncrement((long *)v);
> +}
> +
>  static INLINE void
>  p_atomic_dec(int32_t *v)
>  {
> @@ -298,6 +318,12 @@ p_atomic_dec(int32_t *v)
>  }
>  
>  static INLINE int32_t
> +p_atomic_dec_return(int32_t *v)
> +{
> +   return _InterlockedDecrement((long *)v);
> +}
> +
> +static INLINE int32_t
>  p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
>  {
>     return _InterlockedCompareExchange((long *)v, _new, old);
> 

I'm afraid only providing the functions for some of the ifdefs doesn't
look acceptable to me, you should implement them for all (shouldn't be
too difficult).
Also, the function definition should probably say it does return the
actual new value (note that in case of the msvc intrinsics this is
actually only really true for win98/nt4 and newer but I guess that's
good enough, or maybe you only depend on negative/zero/positive value in
which case it should also work).
Though do you really have cases where you can go below zero? Otherwise
p_atomic_dec_zero() should be suffcient.

Roland


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to