Pigweed
 
Loading...
Searching...
No Matches
pw::sync::BorrowedPointer< GuardedType, LockType > Class Template Reference

#include <borrow.h>

Public Member Functions

 ~BorrowedPointer ()
 Release the lock on destruction.
 
template<typename G , typename L >
 BorrowedPointer (BorrowedPointer< G, L > &&other)
 
template<typename G , typename L >
BorrowedPointeroperator= (BorrowedPointer< G, L > &&other)
 
 BorrowedPointer (const BorrowedPointer &)=delete
 
BorrowedPointeroperator= (const BorrowedPointer &)=delete
 
GuardedType * operator-> ()
 Provides access to the borrowed object's members.
 
const GuardedType * operator-> () const
 Const overload.
 
GuardedType & operator* ()
 
const GuardedType & operator* () const
 Const overload.
 

Friends

template<typename , typename >
class Borrowable
 Allow BorrowedPointer creation inside of Borrowable's acquire methods.
 
template<typename , typename >
class BorrowedPointer
 

Detailed Description

template<typename GuardedType, typename LockType = pw::sync::VirtualBasicLockable>
class pw::sync::BorrowedPointer< GuardedType, LockType >

The BorrowedPointer is an RAII handle which wraps a pointer to a borrowed object along with a held lock which is guarding the object. When destroyed, the lock is released.

Constructor & Destructor Documentation

◆ BorrowedPointer()

template<typename GuardedType , typename LockType = pw::sync::VirtualBasicLockable>
template<typename G , typename L >
pw::sync::BorrowedPointer< GuardedType, LockType >::BorrowedPointer ( BorrowedPointer< G, L > &&  other)
inline

Move-constructs a BorrowedPointer<T> from a BorrowedPointer<U>.

This allows not only pure move construction where GuardedType == G and Lock == L, but also converting construction where GuardedType is a base class of OtherType and Lock is a base class of OtherLock, like `BorrowedPointer<Base> base_ptr(derived_borrowable.acquire());

Postcondition: The other BorrowedPointer is no longer valid and will assert if the GuardedType is accessed.

Member Function Documentation

◆ operator*()

template<typename GuardedType , typename LockType = pw::sync::VirtualBasicLockable>
GuardedType & pw::sync::BorrowedPointer< GuardedType, LockType >::operator* ( )
inline

Provides access to the borrowed object directly.

embed:rst:leading-asterisk
 
*  .. note::
*     The member of pointer member access operator, ``operator->()``, is
*     recommended over this API as this is prone to leaking references.
*     However, this is sometimes necessary.
* 
*  .. warning:
*     Be careful not to leak references to the borrowed object!
*  

◆ operator=()

template<typename GuardedType , typename LockType = pw::sync::VirtualBasicLockable>
template<typename G , typename L >
BorrowedPointer & pw::sync::BorrowedPointer< GuardedType, LockType >::operator= ( BorrowedPointer< G, L > &&  other)
inline

Move-assigns a BorrowedPointer<T> from a BorrowedPointer<U>.

This allows not only pure move construction where GuardedType == OtherType and Lock == OtherLock, but also converting construction where GuardedType is a base class of OtherType and Lock is a base class of OtherLock, like `BorrowedPointer<Base> base_ptr = derived_borrowable.acquire();

Postcondition: The other BorrowedPointer is no longer valid and will assert if the GuardedType is accessed.

Friends And Related Function Documentation

◆ BorrowedPointer

template<typename GuardedType , typename LockType = pw::sync::VirtualBasicLockable>
template<typename , typename >
friend class BorrowedPointer
friend

Allow converting move constructor and assignment to access fields of this class.


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