15 #ifndef GRPC_CORE_LIB_GPRPP_SINGLE_SET_PTR_H
16 #define GRPC_CORE_LIB_GPRPP_SINGLE_SET_PTR_H
27 template <
class T,
class Deleter = std::default_delete<T>>
38 :
p_(other.p_.exchange(
nullptr)) {}
40 Set(other.p_.exchange(
nullptr, std::memory_order_acq_rel));
48 T* expected =
nullptr;
49 if (!
p_.compare_exchange_strong(expected,
ptr, std::memory_order_acq_rel,
50 std::memory_order_acquire)) {
62 void Reset() {
Delete(
p_.exchange(
nullptr, std::memory_order_acq_rel)); }
65 T* p =
p_.load(std::memory_order_acquire);
70 T* p =
p_.load(std::memory_order_acquire);
79 if (p ==
nullptr)
return;
82 std::atomic<T*>
p_{
nullptr};
87 #endif // GRPC_CORE_LIB_GPRPP_SINGLE_SET_PTR_H