# 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.

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:
  1. Default constructor.
  2. Constructor with lock.
[none] ~LockGuard Non-virtual destructor.
void setLockObject Set lock object.
CoroutineStarter lockAsync Multiple implementations:
  1. Lock the lock.
  2. Lock and guard the lock.
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

  1. Default constructor.
    LockGuard()
    
  2. 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

  1. Lock the lock.
    CoroutineStarter lockAsync()
    
  2. Lock and guard the lock.
    Same as setLockObject(lock) + lockAsync();.
    CoroutineStarter lockAsync(Lock* lock)
    

# LockGuard::lockAsyncInline

Lock the lock. (Async-inline usage. Should be called from a separate method of coroutine).

Action lockAsyncInline(oatpp::async::Action&& nextAction)

# LockGuard::unlock

Unlock guarded lock.

void unlock()

# synchronize

Namespace: oatpp::async

Synchronize coroutine execution by lock.

CoroutineStarter synchronize(oatpp::async::Lock *lock, CoroutineStarter&& starter)