proxygen
folly::detail::shared_ptr_internals Class Reference

#include <AtomicSharedPtr-detail.h>

Classes

struct  access_base
 
struct  access_counted_ptr_ptr
 
struct  access_refcount
 
struct  access_shared_ptr
 
struct  access_shared_ptr_ptr
 
struct  access_use_count
 
struct  access_weak_count
 
struct  Rob
 

Public Types

typedef std::__shared_count< std::_S_atomic > shared_count
 
typedef std::_Sp_counted_base< std::_S_atomic > counted_base
 
template<typename T >
using CountedPtr = std::shared_ptr< T >
 

Static Public Member Functions

template<typename T , typename... Args>
static std::shared_ptr< Tmake_ptr (Args &&...args)
 
template<typename T >
static counted_baseget_counted_base (const std::shared_ptr< T > &bar)
 
static void inc_shared_count (counted_base *base, long count)
 
template<typename T >
static void release_shared (counted_base *base, long count)
 
template<typename T >
static Tget_shared_ptr (counted_base *base)
 
template<typename T >
static Trelease_ptr (std::shared_ptr< T > &p)
 
template<typename T >
static std::shared_ptr< Tget_shared_ptr_from_counted_base (counted_base *base, bool inc=true)
 

Detailed Description

Definition at line 33 of file AtomicSharedPtr-detail.h.

Member Typedef Documentation

typedef std::_Sp_counted_base<std::_S_atomic> folly::detail::shared_ptr_internals::counted_base

Definition at line 40 of file AtomicSharedPtr-detail.h.

template<typename T >
using folly::detail::shared_ptr_internals::CountedPtr = std::shared_ptr<T>

Definition at line 42 of file AtomicSharedPtr-detail.h.

typedef std::__shared_count<std::_S_atomic> folly::detail::shared_ptr_internals::shared_count

Definition at line 39 of file AtomicSharedPtr-detail.h.

Member Function Documentation

template<typename T >
shared_ptr_internals::counted_base * folly::detail::shared_ptr_internals::get_counted_base ( const std::shared_ptr< T > &  bar)
inlinestatic

Definition at line 133 of file AtomicSharedPtr-detail.h.

References folly::detail::shared_ptr_internals::access_shared_ptr::fieldPtr, and ptr.

133  {
134  // reinterpret_pointer_cast<const void>
135  // Not quite C++ legal, but explicit template instantiation access to
136  // private members requires full type name (i.e. shared_ptr<const void>, not
137  // shared_ptr<T>)
138  const std::shared_ptr<const void>& ptr(
139  reinterpret_cast<const std::shared_ptr<const void>&>(bar));
140  return (ptr.*fieldPtr(access_shared_ptr{})).*fieldPtr(access_base{});
141 }
void * ptr
template<typename T >
T * folly::detail::shared_ptr_internals::get_shared_ptr ( counted_base base)
inlinestatic

Definition at line 171 of file AtomicSharedPtr-detail.h.

References folly::detail::shared_ptr_internals::access_shared_ptr::fieldPtr, ptr, and folly::T.

171  {
172  // See if this was a make_shared allocation
173  auto inplace = base->_M_get_deleter(typeid(std::_Sp_make_shared_tag));
174  if (inplace) {
175  return (T*)inplace;
176  }
177  // Could also be a _Sp_counted_deleter, but the layout is the same
178  using derived_type = std::_Sp_counted_ptr<const void*, std::_S_atomic>;
179  auto ptr = reinterpret_cast<derived_type*>(base);
180  return (T*)(ptr->*fieldPtr(access_counted_ptr_ptr{}));
181 }
void * ptr
folly::std T
template<typename T >
std::shared_ptr< T > folly::detail::shared_ptr_internals::get_shared_ptr_from_counted_base ( counted_base base,
bool  inc = true 
)
inlinestatic

Definition at line 195 of file AtomicSharedPtr-detail.h.

References folly::detail::shared_ptr_internals::access_shared_ptr::fieldPtr, inc_shared_count(), and folly::gen::move.

197  {
198  if (!base) {
199  return nullptr;
200  }
201  std::shared_ptr<const void> newp;
202  if (inc) {
203  inc_shared_count(base, 1);
204  }
205  newp.*fieldPtr(access_shared_ptr_ptr{}) =
206  get_shared_ptr<const void>(base); // _M_ptr
207  (newp.*fieldPtr(access_refcount{})).*fieldPtr(access_base{}) = base;
208  // reinterpret_pointer_cast<T>
209  auto res = reinterpret_cast<std::shared_ptr<T>*>(&newp);
210  return std::move(*res);
211 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static void inc_shared_count(counted_base *base, long count)
void folly::detail::shared_ptr_internals::inc_shared_count ( counted_base base,
long  count 
)
inlinestatic

Definition at line 143 of file AtomicSharedPtr-detail.h.

References folly::detail::shared_ptr_internals::access_shared_ptr::fieldPtr, and FOLLY_SAFE_CHECK.

Referenced by get_shared_ptr_from_counted_base().

145  {
146  // Check that we don't exceed the maximum number of atomic_shared_ptrs.
147  // Consider setting EXTERNAL_COUNT lower if this CHECK is hit.
149  base->_M_get_use_count() + count < INT_MAX, "atomic_shared_ptr overflow");
150  __gnu_cxx::__atomic_add_dispatch(
151  &(base->*fieldPtr(access_use_count{})), count);
152 }
#define FOLLY_SAFE_CHECK(expr, msg)
Definition: SafeAssert.h:35
int * count
template<typename T , typename... Args>
static std::shared_ptr<T> folly::detail::shared_ptr_internals::make_ptr ( Args &&...  args)
inlinestatic

Definition at line 36 of file AtomicSharedPtr-detail.h.

References testing::Args().

36  {
37  return std::make_shared<T>(std::forward<Args...>(args...));
38  }
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
template<typename T >
T * folly::detail::shared_ptr_internals::release_ptr ( std::shared_ptr< T > &  p)
inlinestatic

Definition at line 184 of file AtomicSharedPtr-detail.h.

References folly::detail::shared_ptr_internals::access_shared_ptr::fieldPtr, and ptr.

184  {
185  auto res = p.get();
186  std::shared_ptr<const void>& ptr(
187  reinterpret_cast<std::shared_ptr<const void>&>(p));
188  ptr.*fieldPtr(access_shared_ptr_ptr{}) = nullptr;
189  (ptr.*fieldPtr(access_refcount{})).*fieldPtr(access_base{}) = nullptr;
190  return res;
191 }
void * ptr
template<typename T >
void folly::detail::shared_ptr_internals::release_shared ( counted_base base,
long  count 
)
inlinestatic

Definition at line 155 of file AtomicSharedPtr-detail.h.

References folly::detail::shared_ptr_internals::access_shared_ptr::fieldPtr.

157  {
158  // If count == 1, this is equivalent to base->_M_release()
159  if (__gnu_cxx::__exchange_and_add_dispatch(
160  &(base->*fieldPtr(access_use_count{})), -count) == count) {
161  base->_M_dispose();
162 
163  if (__gnu_cxx::__exchange_and_add_dispatch(
164  &(base->*fieldPtr(access_weak_count{})), -1) == 1) {
165  base->_M_destroy();
166  }
167  }
168 }
int * count

The documentation for this class was generated from the following file: