Security::LockingPointer< T, UnLocker, Locker > Class Template Reference

#include <LockingPointer.h>

Inheritance diagram for Security::LockingPointer< T, UnLocker, Locker >:
Collaboration diagram for Security::LockingPointer< T, UnLocker, Locker >:

Public Types

typedef Security::LockingPointer< T, UnLocker, Locker > SelfType
 a helper label to simplify this objects API definitions below More...
 

Public Member Functions

constexpr LockingPointer ()
 constructs a nil smart pointer More...
 
constexpr LockingPointer (std::nullptr_t)
 constructs a nil smart pointer from nullptr More...
 
 LockingPointer (T *t)
 
 ~LockingPointer ()
 use the custom UnLocker to unlock any value still stored. More...
 
 LockingPointer (const SelfType &o)
 
const SelfTypeoperator= (const SelfType &o)
 
 LockingPointer (SelfType &&o)
 
SelfTypeoperator= (SelfType &&o)
 
bool operator! () const
 
 operator bool () const
 
bool operator== (const SelfType &o) const
 
bool operator!= (const SelfType &o) const
 
T & operator* () const
 
T * operator-> () const
 
T * get () const
 Returns raw and possibly nullptr pointer. More...
 
void resetWithoutLocking (T *t)
 Reset raw pointer - unlock any previous one and save new one without locking. More...
 
void resetAndLock (T *t)
 
void reset ()
 Forget the raw pointer - unlock if any value was set. Become a nil pointer. More...
 
T * release ()
 Forget the raw pointer without unlocking it. Become a nil pointer. More...
 

Private Member Functions

void lock (T *t)
 The lock() method increments Object's reference counter. More...
 
void unlock ()
 

Private Attributes

T * raw
 

Detailed Description

template<typename T, void(*)(T *t) UnLocker, class Locker = NilFunctor>
class Security::LockingPointer< T, UnLocker, Locker >

A shared pointer to a reference-counting Object with library-specific absorption, locking, and unlocking implementations. The API largely follows std::shared_ptr.

The constructor and the resetWithoutLocking() method import a raw Object pointer. Normally, reset() would lock(), but libraries like OpenSSL pre-lock objects before they are fed to LockingPointer, necessitating this resetWithoutLocking() customization hook.

Definition at line 48 of file LockingPointer.h.

Member Typedef Documentation

◆ SelfType

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
typedef Security::LockingPointer<T, UnLocker, Locker> Security::LockingPointer< T, UnLocker, Locker >::SelfType

Definition at line 52 of file LockingPointer.h.

Constructor & Destructor Documentation

◆ LockingPointer() [1/5]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
constexpr Security::LockingPointer< T, UnLocker, Locker >::LockingPointer ( )
inlineconstexpr

Definition at line 55 of file LockingPointer.h.

◆ LockingPointer() [2/5]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
constexpr Security::LockingPointer< T, UnLocker, Locker >::LockingPointer ( std::nullptr_t  )
inlineconstexpr

Definition at line 58 of file LockingPointer.h.

◆ LockingPointer() [3/5]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
Security::LockingPointer< T, UnLocker, Locker >::LockingPointer ( T *  t)
inlineexplicit

Construct directly from a (possibly nil) raw pointer. If the supplied pointer is not nil, it is expected that its producer has already created one reference lock for the object pointed to, and our destructor will do the matching unlock.

Definition at line 66 of file LockingPointer.h.

References Security::LockingPointer< T, UnLocker, Locker >::resetWithoutLocking().

◆ ~LockingPointer()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
Security::LockingPointer< T, UnLocker, Locker >::~LockingPointer ( )
inline

◆ LockingPointer() [4/5]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
Security::LockingPointer< T, UnLocker, Locker >::LockingPointer ( const SelfType o)
inline

◆ LockingPointer() [5/5]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
Security::LockingPointer< T, UnLocker, Locker >::LockingPointer ( SelfType &&  o)
inline

Member Function Documentation

◆ get()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
T * Security::LockingPointer< T, UnLocker, Locker >::get ( void  ) const
inline

◆ lock()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
void Security::LockingPointer< T, UnLocker, Locker >::lock ( T *  t)
inlineprivate

◆ operator bool()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
Security::LockingPointer< T, UnLocker, Locker >::operator bool ( ) const
inlineexplicit

◆ operator!()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
bool Security::LockingPointer< T, UnLocker, Locker >::operator! ( ) const
inline

◆ operator!=()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
bool Security::LockingPointer< T, UnLocker, Locker >::operator!= ( const SelfType o) const
inline

◆ operator*()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
T & Security::LockingPointer< T, UnLocker, Locker >::operator* ( ) const
inline

◆ operator->()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
T * Security::LockingPointer< T, UnLocker, Locker >::operator-> ( ) const
inline

◆ operator=() [1/2]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
const SelfType & Security::LockingPointer< T, UnLocker, Locker >::operator= ( const SelfType o)
inline

◆ operator=() [2/2]

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
SelfType & Security::LockingPointer< T, UnLocker, Locker >::operator= ( SelfType &&  o)
inline

◆ operator==()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
bool Security::LockingPointer< T, UnLocker, Locker >::operator== ( const SelfType o) const
inline

◆ release()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
T * Security::LockingPointer< T, UnLocker, Locker >::release ( )
inline

◆ reset()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
void Security::LockingPointer< T, UnLocker, Locker >::reset ( void  )
inline

◆ resetAndLock()

◆ resetWithoutLocking()

◆ unlock()

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
void Security::LockingPointer< T, UnLocker, Locker >::unlock ( )
inlineprivate

Become a nil pointer. Decrements any pointed-to Object's reference counter using UnLocker which ideally destroys the object when the counter reaches zero.

Definition at line 137 of file LockingPointer.h.

References Security::LockingPointer< T, UnLocker, Locker >::raw.

Referenced by Security::LockingPointer< T, UnLocker, Locker >::~LockingPointer(), Security::LockingPointer< T, UnLocker, Locker >::reset(), and Security::LockingPointer< T, UnLocker, Locker >::resetWithoutLocking().

Member Data Documentation

◆ raw

template<typename T , void(*)(T *t) UnLocker, class Locker = NilFunctor>
T* Security::LockingPointer< T, UnLocker, Locker >::raw
private

Normally, no other code will have this raw pointer.

However, OpenSSL does some strange and not always consistent things. OpenSSL library may keep its own internal raw pointers and manage their reference counts independently, or it may not. This varies between API functions, though it is usually documented.

This means the caller code needs to be carefully written to use the correct reset method and avoid the raw-pointer constructor unless OpenSSL function producing the pointer is clearly documented as incrementing a lock for it.

Definition at line 156 of file LockingPointer.h.

Referenced by Security::LockingPointer< T, UnLocker, Locker >::get(), Security::LockingPointer< T, UnLocker, Locker >::operator bool(), Security::LockingPointer< T, UnLocker, Locker >::operator!(), Security::LockingPointer< T, UnLocker, Locker >::operator!=(), Security::LockingPointer< T, UnLocker, Locker >::operator*(), Security::LockingPointer< T, UnLocker, Locker >::operator->(), Security::LockingPointer< T, UnLocker, Locker >::operator=(), Security::LockingPointer< T, UnLocker, Locker >::operator==(), Security::LockingPointer< T, UnLocker, Locker >::release(), Security::LockingPointer< T, UnLocker, Locker >::resetWithoutLocking(), and Security::LockingPointer< T, UnLocker, Locker >::unlock().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors