Pigweed
 
Loading...
Searching...
No Matches
pw::sync::InlineBorrowable< GuardedType, Lock, LockInterface > Class Template Reference

#include <inline_borrowable.h>

Inheritance diagram for pw::sync::InlineBorrowable< GuardedType, Lock, LockInterface >:
pw::sync::Borrowable< GuardedType, LockType >

Public Member Functions

constexpr InlineBorrowable ()
 Construct the guarded object and lock using their default constructors.
 
template<typename... Args>
constexpr InlineBorrowable (std::in_place_t, Args &&... args)
 
template<typename... ObjectArgs, typename... LockArgs>
constexpr InlineBorrowable (std::tuple< ObjectArgs... > &&object_args, std::tuple< LockArgs... > &&lock_args=std::make_tuple())
 
template<typename ObjectConstructor , typename LockConstructor = Lock(), typename = std::enable_if_t< std::is_invocable_r_v<GuardedType&&, ObjectConstructor>>, typename = std::enable_if_t< std::is_invocable_r_v<Lock&&, LockConstructor>>>
constexpr InlineBorrowable (const ObjectConstructor &object_ctor, const LockConstructor &lock_ctor=internal::DefaultConstruct< Lock >)
 
template<typename ObjectConstructor , typename LockConstructor = Lock(), typename = std::enable_if_t< std::is_invocable_r_v<GuardedType&&, ObjectConstructor>>, typename = std::enable_if_t< std::is_invocable_r_v<Lock&&, LockConstructor>>>
constexpr InlineBorrowable (ObjectConstructor &object_ctor, const LockConstructor &lock_ctor=internal::DefaultConstruct< Lock >)
 
template<typename ObjectConstructor , typename LockConstructor = Lock(), typename = std::enable_if_t< std::is_invocable_r_v<GuardedType&&, ObjectConstructor>>, typename = std::enable_if_t< std::is_invocable_r_v<Lock&&, LockConstructor>>>
constexpr InlineBorrowable (const ObjectConstructor &object_ctor, LockConstructor &lock_ctor)
 
template<typename ObjectConstructor , typename LockConstructor = Lock(), typename = std::enable_if_t< std::is_invocable_r_v<GuardedType&&, ObjectConstructor>>, typename = std::enable_if_t< std::is_invocable_r_v<Lock&&, LockConstructor>>>
constexpr InlineBorrowable (ObjectConstructor &object_ctor, LockConstructor &lock_ctor)
 
- Public Member Functions inherited from pw::sync::Borrowable< GuardedType, LockType >
constexpr Borrowable (GuardedType &object, LockType &lock) noexcept
 
template<typename U >
constexpr Borrowable (const Borrowable< U, LockType > &other)
 
 Borrowable (const Borrowable &)=default
 
Borrowableoperator= (const Borrowable &)=default
 
 Borrowable (Borrowable &&other)=default
 
Borrowableoperator= (Borrowable &&other)=default
 
BorrowedPointer< GuardedType, LockType > acquire () const
 Blocks indefinitely until the object can be borrowed. Failures are fatal.
 
template<int &... ExplicitArgumentBarrier, typename T = LockType, typename = std::enable_if_t<is_lockable_v<T>>>
std::optional< BorrowedPointer< GuardedType, LockType > > try_acquire () const
 

Detailed Description

template<typename GuardedType, typename Lock = pw::sync::VirtualMutex, typename LockInterface = pw::sync::VirtualBasicLockable>
class pw::sync::InlineBorrowable< GuardedType, Lock, LockInterface >

InlineBorrowable holds an object of GuardedType and a Lock that guards access to the object. It should be used when an object should be guarded for its entire lifecycle by a single lock.

This object should be shared with other componetns as a reference of type Borrowable<GuardedType, LockInterface>.

Constructor & Destructor Documentation

◆ InlineBorrowable() [1/3]

template<typename GuardedType , typename Lock = pw::sync::VirtualMutex, typename LockInterface = pw::sync::VirtualBasicLockable>
template<typename... Args>
constexpr pw::sync::InlineBorrowable< GuardedType, Lock, LockInterface >::InlineBorrowable ( std::in_place_t  ,
Args &&...  args 
)
inlineexplicitconstexpr

Construct the guarded object by providing its constructor arguments inline. The lock is constructed using its default constructor.

This constructor supports list initialization for arrays, structs, and other objects such as std::array.

Example:

InlineBorrowable<Foo> foo(std::in_place, foo_arg1, foo_arg2);
InlineBorrowable<std::array<int, 2>> foo_array(std::in_place, 1, 2);
Definition: inline_borrowable.h:37

◆ InlineBorrowable() [2/3]

template<typename GuardedType , typename Lock = pw::sync::VirtualMutex, typename LockInterface = pw::sync::VirtualBasicLockable>
template<typename... ObjectArgs, typename... LockArgs>
constexpr pw::sync::InlineBorrowable< GuardedType, Lock, LockInterface >::InlineBorrowable ( std::tuple< ObjectArgs... > &&  object_args,
std::tuple< LockArgs... > &&  lock_args = std::make_tuple() 
)
inlineexplicitconstexpr

Construct the guarded object and lock by providing their construction parameters using separate tuples. The 2nd tuple can be ommitted to construct the lock using its default constructor.

Example:

InlineBorrowable<Foo> foo(std::forward_as_tuple(foo_arg1, foo_arg2));
std::forward_as_tuple(foo_arg1, foo_arg2),
std::forward_as_tuple(lock_arg1, lock_arg2));
Note
This constructor only supports list initialization with C++20 or later, because it requires https://wg21.link/p0960.

◆ InlineBorrowable() [3/3]

template<typename GuardedType , typename Lock = pw::sync::VirtualMutex, typename LockInterface = pw::sync::VirtualBasicLockable>
template<typename ObjectConstructor , typename LockConstructor = Lock(), typename = std::enable_if_t< std::is_invocable_r_v<GuardedType&&, ObjectConstructor>>, typename = std::enable_if_t< std::is_invocable_r_v<Lock&&, LockConstructor>>>
constexpr pw::sync::InlineBorrowable< GuardedType, Lock, LockInterface >::InlineBorrowable ( const ObjectConstructor &  object_ctor,
const LockConstructor &  lock_ctor = internal::DefaultConstruct<Lock> 
)
inlineexplicitconstexpr

Construct the guarded object and lock by providing factory functions. The 2nd callable can be ommitted to construct the lock using its default constructor.

Example:

InlineBorrowable<Foo> foo([&]{ return Foo{foo_arg1, foo_arg2}; });
InlineBorrowable<Foo, MyLock> foo_lock(
[&]{ return Foo{foo_arg1, foo_arg2}; }
[&]{ return MyLock{lock_arg1, lock_arg2}; }

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