QRecursiveMutex Class | Qt Core (original) (raw)
Member Function Documentation
[constexpr noexcept]
QRecursiveMutex::QRecursiveMutex()
Constructs a new recursive mutex. The mutex is created in an unlocked state.
[noexcept]
QRecursiveMutex::~QRecursiveMutex()
Destroys the mutex.
Warning: Destroying a locked mutex may result in undefined behavior.
[noexcept(...)]
void QRecursiveMutex::lock()
Locks the mutex. If another thread has locked the mutex then this call will block until that thread has unlocked it.
Calling this function multiple times on the same mutex from the same thread is allowed.
Note: This function is noexcept when LockIsNoexcept
is true
.
See also unlock().
[noexcept(...), since 6.6]
bool QRecursiveMutex::tryLock(QDeadlineTimer timeout = {})
Attempts to lock the mutex. This function returns true
if the lock was obtained; otherwise it returns false
. If another thread has locked the mutex, this function will wait until timeout expires for the mutex to become available.
If the lock was obtained, the mutex must be unlocked with unlock() before another thread can successfully lock it.
Calling this function multiple times on the same mutex from the same thread is allowed.
This function was introduced in Qt 6.6.
Note: This function is noexcept when LockIsNoexcept
is true
.
[noexcept(...)]
bool QRecursiveMutex::tryLock(int timeout)
Attempts to lock the mutex. This function returns true
if the lock was obtained; otherwise it returns false
. If another thread has locked the mutex, this function will wait for at most timeout milliseconds for the mutex to become available.
Note: Passing a negative number as the timeout is equivalent to calling lock(), i.e. this function will wait forever until mutex can be locked if timeout is negative.
If the lock was obtained, the mutex must be unlocked with unlock() before another thread can successfully lock it.
Calling this function multiple times on the same mutex from the same thread is allowed.
Note: This function is noexcept when LockIsNoexcept
is true
.
[noexcept(...)]
bool QRecursiveMutex::try_lock()
Attempts to lock the mutex. This function returns true
if the lock was obtained; otherwise it returns false
.
This function is provided for compatibility with the Standard Library concept Lockable
. It is equivalent to tryLock().
Note: This function is noexcept when LockIsNoexcept
is true
.
template <typename Rep, typename Period> bool QRecursiveMutex::try_lock_for(std::chrono::duration<Rep, Period> duration)
Attempts to lock the mutex. This function returns true
if the lock was obtained; otherwise it returns false
. If another thread has locked the mutex, this function will wait for at least duration for the mutex to become available.
Note: Passing a negative duration as the duration is equivalent to calling try_lock(). This behavior differs from tryLock().
If the lock was obtained, the mutex must be unlocked with unlock() before another thread can successfully lock it.
Calling this function multiple times on the same mutex from the same thread is allowed.
template <typename Clock, typename Duration> bool QRecursiveMutex::try_lock_until(std::chrono::time_point<Clock, Duration> timePoint)
Attempts to lock the mutex. This function returns true
if the lock was obtained; otherwise it returns false
. If another thread has locked the mutex, this function will wait at least until timePoint for the mutex to become available.
Note: Passing a timePoint which has already passed is equivalent to calling try_lock(). This behavior differs from tryLock().
If the lock was obtained, the mutex must be unlocked with unlock() before another thread can successfully lock it.
Calling this function multiple times on the same mutex from the same thread is allowed.
[noexcept]
void QRecursiveMutex::unlock()
Unlocks the mutex. Attempting to unlock a mutex in a different thread to the one that locked it results in an error. Unlocking a mutex that is not locked results in undefined behavior.
See also lock().