This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Implement allocate_once


The most recent patch looks good to me.

I have a minor comment for future patches:

On Fri, 2018-01-12 at 10:46 +0100, Florian Weimer wrote:
> +  while (true)
> +    {
> +      /* Synchronizes with the acquire MO load in allocate_once.  */
> +      void *expected = NULL;
> +      if (atomic_compare_exchange_weak_release (place, &expected, result))
> +        return result;
> +
> +      /* The failed CAS has relaxed MO semantics, so perform another
> +         acquire MO load.  */
> +      void *other_result = atomic_load_acquire (place);

You could just use expected here, because it has been updated, and ...

> +      if (other_result == NULL)
> +        /* Spurious failure.  Try again.  */
> +        continue;
> +
> +      /* We lost the race.  Free what we allocated and return the
> +         other result.  */

... add an atomic_thread_fence_acquire() here.

> +      if (deallocate == NULL)
> +        free (result);
> +      else
> +        deallocate (closure, result);
> +      return other_result;
> +    }




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]