Re: [PATCH 12/37] drm/i915: Add fetch_and_zero() macro

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

 



On pe, 2016-08-12 at 07:54 +0100, Chris Wilson wrote:
> A simple little macro to clear a pointer and return the old value. This
> is useful for writing
> 
> 	value = *ptr;
> 	if (!value)
> 		return;
> 
> 	*ptr = 0;
> 	...
> 	free(value);
> 
> in a slightly more concise form:
> 
> 	value = fetch_and_zero(ptr);
> 	if (!value)
> 		return;
> 
> 	...
> 	free(value);
> 
> with the idea that this establishes a pattern that may be extended for
> atomic use (using xchg or cmpxchg) i.e. atomic_fetch_and_zero() and
> similar to llist.
> 
> Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
> Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
> Cc: Daniel Vetter <daniel.vetter@xxxxxxxx>
> ---
>  drivers/gpu/drm/i915/i915_drv.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index a4203ff0cf7f..731c67fc9796 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -3903,4 +3903,10 @@ static inline bool __i915_request_irq_complete(struct drm_i915_gem_request *req)
>  	return false;
>  }
>  
> +#define fetch_and_zero(ptr) ({					\
> +	typeof(*ptr) T__ = *(ptr);					\

Looking at container_of etc. it's always __ as prefix.

	const typeof(*ptr) __val = *(ptr);

And we're good to go (with kerneldoc almost ready for core submission
:P);

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>

> +	*(ptr) = (typeof(*ptr))0;					\
> +	T__;								\
> +})
> +
>  #endif
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux