mardi 25 juillet 2017

On the implementation of atomic_exchange_strong_explicit for shared_ptr

Please see this link:

template<typename _Tp>
  bool
  atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p,
                                          shared_ptr<_Tp>* __v,
                                          shared_ptr<_Tp> __w,
                                          memory_order,
                                          memory_order)
  {
    shared_ptr<_Tp> __x; // goes out of scope after __lock
    _Sp_locker __lock{__p, __v};
    owner_less<shared_ptr<_Tp>> __less;
    if (*__p == *__v && !__less(*__p, *__v) && !__less(*__v, *__p))
      {
        __x = std::move(*__p);
        *__p = std::move(__w);
        return true;
      }
    __x = std::move(*__v);
    *__v = *__p;
    return false;
  }

To me it looks like *__p == *__v and !__less(*__p, *__v) && !__less(*__v, *__p) both state the fact that the pointers *__p and *__v are equal. Why are they both used there?

Thanks.

Aucun commentaire:

Enregistrer un commentaire