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

 LockingPointer (T *t=nullptr)
 
 ~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 * 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 53 of file LockingPointer.h.

Member Typedef Documentation

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 57 of file LockingPointer.h.

Constructor & Destructor Documentation

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

Construct directly from a raw pointer. This action requires that the producer of that pointer has already created one reference lock for the object pointed to. Our destructor will do the matching unlock.

Definition at line 65 of file LockingPointer.h.

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

Definition at line 71 of file LockingPointer.h.

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

Definition at line 74 of file LockingPointer.h.

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

Definition at line 82 of file LockingPointer.h.

Member Function Documentation

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

Definition at line 92 of file LockingPointer.h.

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

Definition at line 91 of file LockingPointer.h.

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

Definition at line 94 of file LockingPointer.h.

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

Definition at line 96 of file LockingPointer.h.

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

Definition at line 77 of file LockingPointer.h.

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

Definition at line 85 of file LockingPointer.h.

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

Definition at line 93 of file LockingPointer.h.

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

Definition at line 118 of file LockingPointer.h.

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

Definition at line 115 of file LockingPointer.h.

template<typename T, void(*)(T *t) UnLocker, class Locker = NilFunctor>
void Security::LockingPointer< T, UnLocker, Locker >::resetAndLock ( T *  t)
inline
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 135 of file LockingPointer.h.

Referenced by Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::reset(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::resetWithoutLocking(), and Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::~LockingPointer().

Member Data Documentation

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 carefuly 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 154 of file LockingPointer.h.

Referenced by Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::get(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::operator bool(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::operator!(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::operator!=(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::operator->(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::operator=(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::operator==(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::release(), Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::resetWithoutLocking(), and Security::LockingPointer< DH, DH_free_cpp, HardFun< int, DH *, DH_up_ref > >::unlock().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors