From dd5a72f2ef12333dff288994a9c778523a2adf78 Mon Sep 17 00:00:00 2001 From: Maged Michael Date: Fri, 20 Jan 2017 12:20:31 -0800 Subject: [PATCH] Made atomics generic in hazptr_owner member functions Summary: As suggested by the C++ committee in November 2016, made atomics generic to allow other atomic types (e.g., folly::DeterministicAtomic), Also removed obsolete comments. Reviewed By: davidtgoldblatt Differential Revision: D4443355 fbshipit-source-id: d9e21a959f2c7e3dd07c0ed4808236da80ef6dcd --- folly/experimental/hazptr/hazptr-impl.h | 14 ++++++++++---- folly/experimental/hazptr/hazptr.h | 24 +++++------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/folly/experimental/hazptr/hazptr-impl.h b/folly/experimental/hazptr/hazptr-impl.h index 8e98d952..1ed15244 100644 --- a/folly/experimental/hazptr/hazptr-impl.h +++ b/folly/experimental/hazptr/hazptr-impl.h @@ -78,9 +78,11 @@ hazptr_owner::~hazptr_owner() { } template -inline bool hazptr_owner::try_protect( - T*& ptr, - const std::atomic& src) noexcept { +template +inline bool hazptr_owner::try_protect(T*& ptr, const A& src) noexcept { + static_assert( + std::is_same().load()), T*>::value, + "Return type of A::load() must be T*"); DEBUG_PRINT(this << " " << ptr << " " << &src); set(ptr); T* p = src.load(); @@ -93,7 +95,11 @@ inline bool hazptr_owner::try_protect( } template -inline T* hazptr_owner::get_protected(const std::atomic& src) noexcept { +template +inline T* hazptr_owner::get_protected(const A& src) noexcept { + static_assert( + std::is_same().load()), T*>::value, + "Return type of A::load() must be T*"); T* p = src.load(); while (!try_protect(p, src)) {} DEBUG_PRINT(this << " " << p << " " << &src); diff --git a/folly/experimental/hazptr/hazptr.h b/folly/experimental/hazptr/hazptr.h index 9ba9e2e8..464dc1f3 100644 --- a/folly/experimental/hazptr/hazptr.h +++ b/folly/experimental/hazptr/hazptr.h @@ -19,6 +19,7 @@ #include #include #include +#include /* Stand-in for C++17 std::pmr::memory_resource */ #include @@ -120,10 +121,12 @@ template class hazptr_owner { /** Hazard pointer operations */ /* Returns a protected pointer from the source */ - T* get_protected(const std::atomic& src) noexcept; + template > + T* get_protected(const A& src) noexcept; /* Return true if successful in protecting ptr if src == ptr after * setting the hazard pointer. Otherwise sets ptr to src. */ - bool try_protect(T*& ptr, const std::atomic& src) noexcept; + template > + bool try_protect(T*& ptr, const A& src) noexcept; /* Set the hazard pointer to ptr */ void set(const T* ptr) noexcept; /* Clear the hazard pointer */ @@ -146,21 +149,4 @@ void swap(hazptr_owner&, hazptr_owner&) noexcept; } // namespace hazptr } // namespace folly -//////////////////////////////////////////////////////////////////////////////// -/// Notes -//////////////////////////////////////////////////////////////////////////////// - -/* The hazptr_obj_base template uses a reclamation function as a - * parameter for the retire() member function instead of taking an - * allocator template as an extra template parameter because objects - * of the same type may need different reclamation functions. */ - -/* The hazptr interface supports reclamation by one domain at a - * time. If an abject belongs to multiple domains simultaneously, a - * workaround may be to design reclamation functions to form a series - * of retirements from one domain to the next until it reaches the - * final domain in the series that finally reclaims the object. */ - -//////////////////////////////////////////////////////////////////////////////// - #include "hazptr-impl.h" -- 2.34.1