YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
yaclib::Mutex< Batching, FIFO > Class Template Referencefinal

Mutex for coroutines. More...

#include <mutex.hpp>

Inheritance diagram for yaclib::Mutex< Batching, FIFO >:
[legend]
Collaboration diagram for yaclib::Mutex< Batching, FIFO >:
[legend]

Public Types

using Base = detail::MutexImpl< FIFO, Batching >
 

Public Member Functions

auto TryGuard () noexcept
 Try to lock mutex and create UniqueGuard for it.
 
auto Guard () noexcept
 Lock mutex and create UniqueGuard for it.
 
auto GuardSticky () noexcept
 Lock mutex and create StickyGuard for it.
 
auto Lock () noexcept
 Lock mutex.
 
auto Unlock () noexcept
 The best way to unlock mutex, if you interested in batched critical section.
 
auto UnlockOn (IExecutor &e) noexcept
 This method is an optimization for Unlock() and On()
 
bool TryLock () noexcept
 Try to lock mutex return true if mutex was locked, false otherwise.
 
void UnlockHere () noexcept
 The general way to unlock mutex, mainly for RAII.
 

Static Public Member Functions

template<typename To , typename From >
static autoCast (From &from) noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from yaclib::detail::MutexImpl< FIFO, Batching >
bool TryLockAwait () noexcept
 
bool AwaitLock (BaseCore &curr) noexcept
 
bool TryUnlockAwait () noexcept
 
YACLIB_INLINE bool BatchingPossible () const noexcept
 
void UnlockHereAwait () noexcept
 
auto AwaitUnlock (BaseCore &curr) noexcept
 
auto AwaitUnlockOn (BaseCore &curr, IExecutor &executor) noexcept
 
bool TryLock () noexcept
 
void UnlockHere () noexcept
 

Detailed Description

template<bool Batching = true, bool FIFO = false>
class yaclib::Mutex< Batching, FIFO >

Mutex for coroutines.

Note
It does not block execution thread, only coroutine

Definition at line 196 of file mutex.hpp.

Member Typedef Documentation

◆ Base

template<bool Batching = true, bool FIFO = false>
using yaclib::Mutex< Batching, FIFO >::Base = detail::MutexImpl<FIFO, Batching>

Definition at line 198 of file mutex.hpp.

Member Function Documentation

◆ Cast()

template<bool Batching = true, bool FIFO = false>
template<typename To , typename From >
static auto & yaclib::Mutex< Batching, FIFO >::Cast ( From &  from)
inlinestaticnoexcept

Definition at line 285 of file mutex.hpp.

References yaclib::MakeContract().

◆ Guard()

template<bool Batching = true, bool FIFO = false>
auto yaclib::Mutex< Batching, FIFO >::Guard ( )
inlinenoexcept

Lock mutex and create UniqueGuard for it.

Returns
Awaitable, which await_resume returns the UniqueGuard

Definition at line 215 of file mutex.hpp.

◆ GuardSticky()

template<bool Batching = true, bool FIFO = false>
auto yaclib::Mutex< Batching, FIFO >::GuardSticky ( )
inlinenoexcept

Lock mutex and create StickyGuard for it.

Returns
Awaitable, which await_resume returns the StickyGuard

Definition at line 224 of file mutex.hpp.

◆ Lock()

template<bool Batching = true, bool FIFO = false>
auto yaclib::Mutex< Batching, FIFO >::Lock ( )
inlinenoexcept

Lock mutex.

Definition at line 237 of file mutex.hpp.

◆ TryGuard()

template<bool Batching = true, bool FIFO = false>
auto yaclib::Mutex< Batching, FIFO >::TryGuard ( )
inlinenoexcept

Try to lock mutex and create UniqueGuard for it.

Note
If we couldn't lock mutex, then UniqueGuard::OwnsLock() will be false
Returns
Awaitable, which await_resume returns the UniqueGuard

Definition at line 206 of file mutex.hpp.

◆ TryLock()

template<bool Batching = true, bool FIFO = false>
bool yaclib::detail::MutexImpl< FIFO, Batching >::TryLock ( )
inlinenoexcept

Try to lock mutex return true if mutex was locked, false otherwise.

Definition at line 97 of file mutex.hpp.

◆ Unlock()

template<bool Batching = true, bool FIFO = false>
auto yaclib::Mutex< Batching, FIFO >::Unlock ( )
inlinenoexcept

The best way to unlock mutex, if you interested in batched critical section.

Definition at line 244 of file mutex.hpp.

◆ UnlockHere()

template<bool Batching = true, bool FIFO = false>
void yaclib::detail::MutexImpl< FIFO, Batching >::UnlockHere ( )
inlinenoexcept

The general way to unlock mutex, mainly for RAII.

Definition at line 101 of file mutex.hpp.

◆ UnlockOn()

template<bool Batching = true, bool FIFO = false>
auto yaclib::Mutex< Batching, FIFO >::UnlockOn ( IExecutor e)
inlinenoexcept

This method is an optimization for Unlock() and On()

Use it instead of

...
co_await mutex.Unlock();
co_await On(e);
...
YACLIB_INLINE detail::OnAwaiter On(IExecutor &e) noexcept
TODO(mkornaukhov03) Add doxygen docs.
Definition on.hpp:11
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25

Typical usage:

...
// auto& executorBeforeCriticalSection = yaclib::kCurrent;
auto guard = co_await mutex.StickyGuard();
...
co_await guard.UnlockOn();
// auto& executorAfterCriticalSection = yaclib::kCurrent;
// assert(&executorBeforeCriticalSection == &executorAfterCriticalSection);
...
Parameters
eexecutor which will be used for code after unlock

Definition at line 273 of file mutex.hpp.

References yaclib::MakeContract().


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