Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
atomic_shared_ptr< X > Class Template Reference

This is an atomic variant of std::shared_ptr, and can be shared by atomic and lock-free means.
. More...

#include <atomic_smart_ptr.h>

Inheritance diagram for atomic_shared_ptr< X >:
Inheritance graph
[legend]

Public Member Functions

template<typename Y >
 atomic_shared_ptr (Y *y)
 
 atomic_shared_ptr (const atomic_shared_ptr< T > &t) noexcept
 
template<typename Y >
 atomic_shared_ptr (const atomic_shared_ptr< Y > &y) noexcept
 
 atomic_shared_ptr (const local_shared_ptr< T > &t) noexcept
 
template<typename Y >
 atomic_shared_ptr (const local_shared_ptr< Y > &y) noexcept
 
 atomic_shared_ptr (atomic_shared_ptr< T > &&t) noexcept
 
template<typename Y >
 atomic_shared_ptr (atomic_shared_ptr< Y > &&y) noexcept
 
atomic_shared_ptroperator= (const atomic_shared_ptr &t) noexcept
 
template<typename Y >
atomic_shared_ptroperator= (const local_shared_ptr< Y > &y) noexcept
 
atomic_shared_ptroperator= (local_shared_ptr< T > &&t) noexcept
 
template<typename Y >
atomic_shared_ptroperator= (local_shared_ptr< Y > &&y) noexcept
 
void reset () noexcept
 The pointer held by this instance is atomically reset to null pointer.
 
template<typename Y >
void reset (Y *y)
 The pointer held by this instance is atomically reset with a pointer y.
 
bool compareAndSet (const local_shared_ptr< T > &oldvalue, const local_shared_ptr< T > &newvalue) noexcept
 
bool compareAndSwap (local_shared_ptr< T > &oldvalue, const local_shared_ptr< T > &newvalue) noexcept
 
bool operator! () const noexcept
 
 operator bool () const noexcept
 
template<typename Y >
bool operator== (const local_shared_ptr< Y > &x) const noexcept
 
template<typename Y >
bool operator== (const atomic_shared_ptr< Y > &x) const noexcept
 
template<typename Y >
bool operator!= (const local_shared_ptr< Y > &x) const noexcept
 
template<typename Y >
bool operator!= (const atomic_shared_ptr< Y > &x) const noexcept
 

Protected Types

typedef atomic_shared_ptr_base
< T, uintptr_t, atomic
< uintptr_t > >::Ref 
Ref
 
typedef atomic_shared_ptr_base
< T, uintptr_t, atomic
< uintptr_t > >::Refcnt 
Refcnt
 
typedef atomic< uintptr_t > RefLocal_
 

Protected Member Functions

Refpref_ () const noexcept
 A pointer to global reference struct.
 
Refcnt refcnt_ () const noexcept
 
Refscan_ () const noexcept
 
Refreserve_scan_ (Refcnt *) const noexcept
 
void leave_scan_ (Ref *) const noexcept
 
template<bool NOSWAP>
bool compareAndSwap_ (local_shared_ptr< T > &oldvalue, const local_shared_ptr< T > &newvalue) noexcept
 
- Protected Member Functions inherited from local_shared_ptr< T, atomic< uintptr_t > >
 local_shared_ptr (atomic< uintptr_t > *y)
 
 local_shared_ptr (atomic< uintptr_t > *y, D deleter)
 
 local_shared_ptr (const atomic_shared_ptr< T > &t) noexcept
 
 local_shared_ptr (const atomic_shared_ptr< atomic< uintptr_t > > &y)
 
 local_shared_ptr (const local_shared_ptr< T, reflocal_var_t > &t) noexcept
 
 local_shared_ptr (const local_shared_ptr< atomic< uintptr_t >, Z > &y) noexcept
 
 local_shared_ptr (local_shared_ptr< T, reflocal_var_t > &&t) noexcept
 
 local_shared_ptr (local_shared_ptr< atomic< uintptr_t >, Z > &&y) noexcept
 
local_shared_ptroperator= (const local_shared_ptr &t) noexcept
 
local_shared_ptroperator= (const local_shared_ptr< atomic< uintptr_t >, Z > &y) noexcept
 
local_shared_ptroperator= (local_shared_ptr &&t) noexcept
 
local_shared_ptroperator= (local_shared_ptr< atomic< uintptr_t >, Z > &&y) noexcept
 
local_shared_ptroperator= (const atomic_shared_ptr< T > &t) noexcept
 
local_shared_ptroperator= (const atomic_shared_ptr< atomic< uintptr_t > > &y) noexcept
 
void swap (local_shared_ptr &x) noexcept
 
void swap (atomic_shared_ptr< T > &x) noexcept
 
void reset () noexcept
 The pointer held by this instance is reset to null pointer.
 
void reset (atomic< uintptr_t > *y)
 The pointer held by this instance is reset with a pointer y.
 
void reset (atomic< uintptr_t > *y, D deleter)
 
T * get () noexcept
 
const T * get () const noexcept
 
T & operator* () noexcept
 
const T & operator* () const noexcept
 
T * operator-> () noexcept
 
const T * operator-> () const noexcept
 
bool operator! () const noexcept
 
 operator bool () const noexcept
 
bool operator== (const local_shared_ptr< atomic< uintptr_t >, Z > &x) const noexcept
 
bool operator== (const atomic_shared_ptr< atomic< uintptr_t > > &x) const noexcept
 
bool operator!= (const local_shared_ptr< atomic< uintptr_t >, Z > &x) const noexcept
 
bool operator!= (const atomic_shared_ptr< atomic< uintptr_t > > &x) const noexcept
 
int use_count () const noexcept
 
bool unique () const noexcept
 
Refpref_ () const noexcept
 A pointer to global reference struct.
 

Friends

template<typename Y , typename Z >
class local_shared_ptr
 
template<typename Y >
class atomic_shared_ptr
 

Additional Inherited Members

Detailed Description

template<typename X>
class atomic_shared_ptr< X >

This is an atomic variant of std::shared_ptr, and can be shared by atomic and lock-free means.
.

atomic_shared_ptr can be shared among threads by the use of operator=(target), swap(target). An instance of atomic_shared_ptr<T> holds:
a) a pointer to atomic_shared_ptr_gref_<T>, which is a struct. consisting of a pointer to a T-type object and a global reference counter.
b) a local (temporary) reference counter, which is embedded in the above pointer by using several LSBs that should be usually zero.
The values of a) and b), m_ref, are atomically handled with CAS machine codes. The purpose of b) the local reference counter is to tell the "observation" to the shared target before increasing the global reference counter. This process is implemented in reserve_scan_().
A function leave_scan_() tries to decrease the local counter first. When it fails, the global counter is decreased.
To swap the pointer and local reference counter (which will be reset to zero), the setter must adds the local counting to the global counter before swapping.

See Also
atomic_unique_ptr, local_shared_ptr, atomic_shared_ptr_test.cpp.

Definition at line 84 of file atomic_smart_ptr.h.

Member Function Documentation

template<typename X>
bool atomic_shared_ptr< X >::compareAndSet ( const local_shared_ptr< T > &  oldvalue,
const local_shared_ptr< T > &  newvalue 
)
noexcept
Returns
true if succeeded.
See Also
compareAndSwap()
template<typename X>
bool atomic_shared_ptr< X >::compareAndSwap ( local_shared_ptr< T > &  oldvalue,
const local_shared_ptr< T > &  newvalue 
)
noexcept
Returns
true if succeeded.
See Also
compareAndSet()
template<typename X>
void atomic_shared_ptr< X >::leave_scan_ ( Ref ) const
inlineprotectednoexcept

Tries to decrease local (temporary) reference counter. In case the reference is lost, leave_scan_() releases the global reference counter instead.

Referenced by atomic_shared_ptr< T >::scan_().

template<typename X>
atomic_shared_ptr& atomic_shared_ptr< X >::operator= ( const atomic_shared_ptr< X > &  t)
inlinenoexcept
Parameters
[in]tThe pointer held by this instance is atomically replaced with that of t.

Definition at line 296 of file atomic_smart_ptr.h.

template<typename X>
template<typename Y >
atomic_shared_ptr& atomic_shared_ptr< X >::operator= ( const local_shared_ptr< Y > &  y)
inlinenoexcept
Parameters
[in]yThe pointer held by this instance is atomically replaced with that of y.

Definition at line 301 of file atomic_smart_ptr.h.

template<typename X>
Refcnt atomic_shared_ptr< X >::refcnt_ ( ) const
inlineprotectednoexcept

Local (temporary) reference counter. Local reference counter is a trick to tell the observation to other threads.

Definition at line 356 of file atomic_smart_ptr.h.

Referenced by atomic_shared_ptr< T >::leave_scan_(), and atomic_shared_ptr< T >::reserve_scan_().

template<typename X>
Ref* atomic_shared_ptr< X >::reserve_scan_ ( Refcnt *  ) const
inlineprotectednoexcept

Atomically scans m_ref and increases the local (temporary) reference counter. use leave_scan_() to release the temporary reference.

Referenced by atomic_shared_ptr< T >::scan_().

template<typename X>
Ref* atomic_shared_ptr< X >::scan_ ( ) const
inlineprotectednoexcept

Atomically scans m_ref and increases the global reference counter. scan_() is used for atomically coping the pointer.

Referenced by local_shared_ptr< typename Transactional::Node< XNode >::Packet >::operator=().


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

Generated for KAME4 by  doxygen 1.8.3