#ifndef GRPC_SRC_CORE_LIB_GPRPP_SINGLE_SET_PTR_H
#define GRPC_SRC_CORE_LIB_GPRPP_SINGLE_SET_PTR_H
#include <grpc/support/port_platform.h>
#include <atomic>
#include <memory>
#include <grpc/support/log.h>
namespace grpc_core {
template <class T, class Deleter = std::default_delete<T>>
class SingleSetPtr {
public:
SingleSetPtr() = default;
explicit SingleSetPtr(T* p) : … { … }
explicit SingleSetPtr(std::unique_ptr<T, Deleter> p) : … { … }
~SingleSetPtr() { … }
SingleSetPtr(const SingleSetPtr&) = delete;
SingleSetPtr& operator=(const SingleSetPtr&) = delete;
SingleSetPtr(SingleSetPtr&& other) noexcept
: … { … }
SingleSetPtr& operator=(SingleSetPtr&& other) noexcept { … }
T* Set(T* ptr) { … }
T* Set(std::unique_ptr<T, Deleter> ptr) { … }
void Reset() { … }
bool is_set() const { … }
T* operator->() const { … }
T& operator*() const { … }
private:
static void Delete(T* p) { … }
std::atomic<T*> p_{nullptr};
};
}
#endif