# Lock.hpp
This File On Github
Ask A Question
API: latest
module: oatpp
#include "oatpp/core/async/Lock.hpp"
# Lock
Lock (mutex) for coroutines/threads synchronization.
- When called from a thread - must be used with std::lock_guard
. - When called from coroutine - must be used with LockGuard.
namespace oatpp { namespace async {
class Lock : private CoroutineWaitList::Listener {}
}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | Lock | Constructor. |
Action | waitAsync | Wait until lock is unlocked, and repeat. |
void | lock | Lock on current thread. !Should NOT be called from within the Coroutine! |
void | unlock | Unlock |
bool | try_lock | Try to lock. |
# Lock::Lock
Constructor.
Lock()
# Lock::waitAsync
Wait until lock is unlocked, and repeat.
- @return - oatpp::async::Action.
Action waitAsync()
# Lock::lock
Lock on current thread. !Should NOT be called from within the Coroutine!
void lock()
# Lock::unlock
Unlock
void unlock()
# Lock::try_lock
Try to lock.
- @return -
true
if the lock was acquired,false
otherwise.
bool try_lock()
# LockGuard
Asynchronous lock guard.
Should be used as a lock guard in coroutines.
namespace oatpp { namespace async {
class LockGuard {}
}}
# Typedefs
Type | Name | Summary |
---|---|---|
oatpp::async::CoroutineStarter | CoroutineStarter | Convenince typedef for oatpp::async::CoroutineStarter. |
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | LockGuard | Multiple implementations:
|
[none] | ~LockGuard | Non-virtual destructor. |
void | setLockObject | Set lock object. |
CoroutineStarter | lockAsync | Multiple implementations:
|
Action | lockAsyncInline | Lock the lock. (Async-inline usage. Should be called from a separate method of coroutine). |
void | unlock | Unlock guarded lock. |
# LockGuard::CoroutineStarter
Convenince typedef for oatpp::async::CoroutineStarter.
typedef oatpp::async::CoroutineStarter CoroutineStarter
# LockGuard::LockGuard
- Default constructor.
LockGuard()
- Constructor with lock.
LockGuard(Lock* lock)
# LockGuard::~LockGuard
Non-virtual destructor.
Will unlock the Lock if owns lock.
~LockGuard()
# LockGuard::setLockObject
Set lock object.
- @param lock - lock object.
void setLockObject(Lock* lock)
# LockGuard::lockAsync
- Lock the lock.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter lockAsync()
- Lock and guard the lock.
Same assetLockObject(lock) + lockAsync();
.- @param lock - lock to lock and guard.
- @return - oatpp::async::CoroutineStarter.
CoroutineStarter lockAsync(Lock* lock)
# LockGuard::lockAsyncInline
Lock the lock. (Async-inline usage. Should be called from a separate method of coroutine).
- @param nextAction - action to take after lock is locked.
- @return - oatpp::async::Action.
Action lockAsyncInline(oatpp::async::Action&& nextAction)
# LockGuard::unlock
Unlock guarded lock.
void unlock()
# synchronize
Namespace: oatpp::async
Synchronize coroutine execution by lock.
- @param lock - Lock for synchronization.
- @param starter - Coroutine to execute in synchronized manner. oatpp::async::CoroutineStarter.
- @return - starter of synchronization coroutine (wrapper coroutine). oatpp::async::CoroutineStarter.
CoroutineStarter synchronize(oatpp::async::Lock *lock, CoroutineStarter&& starter)