[vlc-devel] [PATCH 1/3] vlc_atomic.h: Allow inclusion when building C++

Thomas Guillem thomas at gllm.fr
Tue Dec 15 20:49:20 CET 2020


Set LGTM

On Tue, Dec 15, 2020, at 17:53, Hugo Beauzée-Luyssen wrote:
> ---
>  include/vlc_atomic.h | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/include/vlc_atomic.h b/include/vlc_atomic.h
> index d596259e12..d653adcf45 100644
> --- a/include/vlc_atomic.h
> +++ b/include/vlc_atomic.h
> @@ -18,10 +18,6 @@
>   * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
>   *****************************************************************************/
>  
> -#ifdef __cplusplus
> -# error Not implemented in C++.
> -#endif
> -
>  #ifndef VLC_ATOMIC_H
>  # define VLC_ATOMIC_H
>  
> @@ -31,7 +27,14 @@
>   */
>  
>  # include <assert.h>
> +#ifndef __cplusplus
>  # include <stdatomic.h>
> +#else
> +# include <atomic>
> +using std::atomic_uintptr_t;
> +using std::memory_order_relaxed;
> +using std::memory_order_acq_rel;
> +#endif
>  # include <vlc_common.h>
>  
>  typedef struct vlc_atomic_rc_t {
> @@ -41,13 +44,14 @@ typedef struct vlc_atomic_rc_t {
>  /** Init the RC to 1 */
>  static inline void vlc_atomic_rc_init(vlc_atomic_rc_t *rc)
>  {
> -    atomic_init(&rc->refs, 1);
> +    atomic_init(&rc->refs, (uintptr_t)1);
>  }
>  
>  /** Increment the RC */
>  static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t *rc)
>  {
> -    uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, 1, 
> memory_order_relaxed);
> +    uintptr_t prev = atomic_fetch_add_explicit(&rc->refs, (uintptr_t)1,
> +                                               memory_order_relaxed);
>      vlc_assert(prev);
>      VLC_UNUSED(prev);
>  }
> @@ -55,7 +59,8 @@ static inline void vlc_atomic_rc_inc(vlc_atomic_rc_t 
> *rc)
>  /** Decrement the RC and return true if it reaches 0 */
>  static inline bool vlc_atomic_rc_dec(vlc_atomic_rc_t *rc)
>  {
> -    uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, 1, 
> memory_order_acq_rel);
> +    uintptr_t prev = atomic_fetch_sub_explicit(&rc->refs, (uintptr_t)1,
> +                                               memory_order_acq_rel);
>      vlc_assert(prev);
>      return prev == 1;
>  }
> -- 
> 2.29.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list