Class rw_spinlock

Class Documentation

class legion::core::async::rw_spinlock

Lock used with ::async::readonly_guard and ::async::readwrite_guard.

Note

Read-only operations can happen simultaneously without waiting for each other. Read-only operations will only wait for Read-Write operations to be finished.

Note

Read-Write operations cannot happen simultaneously and will wait for each other. Read-Write operations will also wait for any Read-only operations to be finished. legion::core::async::readonly_guard legion::core::async::readwrite_guard legion::core::async::readonly_multiguard legion::core::async::readwrite_multiguard legion::core::async::mixed_multiguard

Public Functions

rw_spinlock() = default
rw_spinlock(rw_spinlock &&source) noexcept
rw_spinlock &operator=(rw_spinlock &&source) noexcept
rw_spinlock(const rw_spinlock&) = delete
rw_spinlock &operator=(const rw_spinlock&) = delete
void lock(lock_state permissionLevel = lock_state::write, wait_priority priority = wait_priority::real_time) const

Lock for a certain permission level. (locking for idle does nothing)

Note

Locking stacks, locking for readonly multiple times will remain readonly. Locking for write after already being locked for readonly in the same thread will attempt to elevate lock permission of this thread to write. Locking for write multiple times will remain in write.

Parameters
  • permissionLevel:

bool try_lock(lock_state permissionLevel = lock_state::write) const

Try to lock for a certain permission level. If it fails it will return false otherwise true. (locking for idle does nothing)

Note

Locking stacks, locking for readonly multiple times will remain readonly. Locking for write after already being locked for readonly in the same thread will attempt to elevate lock permission of this thread to write. Locking for write multiple times will remain in write.

Return

bool True when locked.

Parameters
  • permissionLevel:

void unlock(lock_state permissionLevel = lock_state::write) const

Unlock from a certain permission level.

Note

If both read and write locks have been requested before and write is unlocked then the lock will return to readonly state.

Parameters
  • permissionLevel:

void lock_shared() const

Locks the rw_spinlockfor shared ownership, blocks if the rw_spinlockis not available.

bool try_lock_shared() const

Tries to lock the rw_spinlockfor shared ownership, returns if the rw_spinlockis not available.

void unlock_shared() const

Unlocks the mutex (shared ownership)

template<typename Guard, typename Func>
inline auto critical_section(const Func &func) const -> decltype(auto)

Execute a function inside a critical section locked by a certain guard.

Return

Return value of func.

Template Parameters
  • Guard: Guard type to lock the lock with.

Parameters
  • func: Function to execute.

Public Static Functions

static void force_release(bool release = true)