#ifndef REF_TRACKED_INL_H_ #error "Direct inclusion of this file is not allowed, include ref_tracked.h" // For the sake of sane code completion. #include "ref_tracked.h" #endif namespace NYT { //////////////////////////////////////////////////////////////////////////////// template TRefCountedTypeKey GetRefCountedTypeKey() { return TRefCountedTypeKey(&typeid(T)); } template Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookie() { static std::atomic cookie{NullRefCountedTypeCookie}; auto cookieValue = cookie.load(std::memory_order::relaxed); if (Y_UNLIKELY(cookieValue == NullRefCountedTypeCookie)) { cookieValue = TRefCountedTrackerFacade::GetCookie( GetRefCountedTypeKey(), sizeof(T), NYT::TSourceLocation()); cookie.store(cookieValue, std::memory_order::relaxed); } return cookieValue; } template Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation(const TSourceLocation& location) { static std::atomic cookie{NullRefCountedTypeCookie}; auto cookieValue = cookie.load(std::memory_order::relaxed); if (Y_UNLIKELY(cookieValue == NullRefCountedTypeCookie)) { cookieValue = TRefCountedTrackerFacade::GetCookie( GetRefCountedTypeKey(), sizeof(T), location); cookie.store(cookieValue, std::memory_order::relaxed); } return cookieValue; } //////////////////////////////////////////////////////////////////////////////// #ifdef YT_ENABLE_REF_COUNTED_TRACKING template TRefTracked::TRefTracked() { auto cookie = GetRefCountedTypeCookie(); TRefCountedTrackerFacade::AllocateInstance(cookie); } template TRefTracked::TRefTracked(const TRefTracked&) { auto cookie = GetRefCountedTypeCookie(); TRefCountedTrackerFacade::AllocateInstance(cookie); } template TRefTracked::TRefTracked(TRefTracked&&) { auto cookie = GetRefCountedTypeCookie(); TRefCountedTrackerFacade::AllocateInstance(cookie); } template TRefTracked::~TRefTracked() { auto cookie = GetRefCountedTypeCookie(); TRefCountedTrackerFacade::FreeInstance(cookie); } #endif //////////////////////////////////////////////////////////////////////////////// } // namespace NYT