X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fexperimental%2Fhazptr%2Fhazptr-impl.h;h=823f2ebf68aa3a2781de014404e3f8762d590388;hp=e287aecc91c45d1d00d92bdac29b3f75f2532a64;hb=7046d43c7e3c18ebc28c62141b8e1eefabce5323;hpb=79376dc7937cd38c10c0c632e3b39c6955ebd734 diff --git a/folly/experimental/hazptr/hazptr-impl.h b/folly/experimental/hazptr/hazptr-impl.h index e287aecc..823f2ebf 100644 --- a/folly/experimental/hazptr/hazptr-impl.h +++ b/folly/experimental/hazptr/hazptr-impl.h @@ -602,6 +602,11 @@ FOLLY_ALWAYS_INLINE hazptr_domain& default_hazptr_domain() { return default_domain_; } +template +FOLLY_ALWAYS_INLINE void hazptr_retire(T* obj, D reclaim) { + default_hazptr_domain().retire(obj, std::move(reclaim)); +} + /** hazptr_rec */ FOLLY_ALWAYS_INLINE void hazptr_rec::set(const void* p) noexcept { @@ -649,6 +654,21 @@ inline const void* hazptr_obj::getObjPtr() const { /** hazptr_domain */ +template +void hazptr_domain::retire(T* obj, D reclaim) { + struct hazptr_retire_node : hazptr_obj { + std::unique_ptr obj_; + + hazptr_retire_node(T* obj, D reclaim) : obj_{obj, std::move(reclaim)} {} + }; + + auto node = new hazptr_retire_node(obj, std::move(reclaim)); + node->reclaim_ = [](hazptr_obj* p) { + delete static_cast(p); + }; + objRetire(node); +} + inline hazptr_domain::~hazptr_domain() { DEBUG_PRINT(this); { /* reclaim all remaining retired objects */