6.0.0-rc4Source

QRecursiveMutex Class

The QRecursiveMutex class provides access serialization between threads. More…

Header#include <QRecursiveMutex>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QRecursiveMutex()
voidlock()
voidunlock()
booltryLock(int timeoutMs = 0)
booltryLock(QDeadlineTimer deadline)
booltry_lock()
booltry_lock_for(std::chrono::duration<Rep, Period> duration)
booltry_lock_until(std::chrono::time_point<Clock, Duration> timePoint)

Detailed Description

A QRecursiveMutex can be locked repeatedly by the thread that already owns it. Each call to lock() or a successful tryLock() must be paired with a call to unlock(); the mutex is released for other threads when the lock count returns to zero.

See also QMutex and QMutexLocker.

Differences from Qt

QRecursiveMutex wraps std::recursive_timed_mutex.

Member Function Documentation

QRecursiveMutex::QRecursiveMutex()

Constructs an unlocked recursive mutex.

void QRecursiveMutex::lock()

Locks the mutex. If another thread holds the lock, this call blocks until the mutex becomes available. A thread that already owns the mutex may call lock() again.

See also unlock() and tryLock().

bool QRecursiveMutex::try_lock()

Attempts to lock the mutex without blocking. Returns true if the lock was obtained; otherwise returns false. This is provided for use with std::lock and std::unique_lock.

See also tryLock().

template <class Rep, class Period>bool QRecursiveMutex::try_lock_for(std::chrono::duration<Rep, Period> duration)

Attempts to lock the mutex, waiting for at most duration. Returns true if the lock was obtained; otherwise returns false. This is provided for use with std::unique_lock.

See also tryLock().

template <class Clock, class Duration>bool QRecursiveMutex::try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)

Attempts to lock the mutex, waiting until timePoint at most. Returns true if the lock was obtained; otherwise returns false. This is provided for use with std::unique_lock.

See also tryLock().

bool QRecursiveMutex::tryLock(int timeoutMs = 0)

Attempts to lock the mutex, waiting up to timeoutMs milliseconds for it to become available. Returns true if the lock was obtained; otherwise returns false.

If timeoutMs is 0, the call returns immediately. A negative timeoutMs waits until the lock is obtained, like lock().

See also lock() and unlock().

bool QRecursiveMutex::tryLock(QDeadlineTimer deadline)

This is an overloaded function.

Attempts to lock the mutex until deadline expires. Returns true if the lock was obtained; otherwise returns false. A deadline that never expires waits like lock().

This function was introduced in 6.6.

void QRecursiveMutex::unlock()

Unlocks the mutex once. The calling thread must own the mutex.

See also lock().