Libkleo
15#include "kleo_export.h"
27 explicit DeferLockType() =
default;
32 explicit TryToLockType() =
default;
38 explicit AdoptLockType() =
default;
45inline constexpr TryToLockType tryToLock{};
57class KLEO_EXPORT UniqueLock
60 UniqueLock()
noexcept;
61 explicit UniqueLock(
QMutex &mutex);
67 template<
typename Clock,
typename Duration>
68 UniqueLock(
QMutex &mutex,
const std::chrono::time_point<Clock, Duration> &timePoint)
69 : mMutex{std::addressof(mutex)}
70 , mOwnsMutex{mMutex->try_lock_until(timePoint)}
74 template<
typename Rep,
typename Period>
75 UniqueLock(
QMutex &mutex,
const std::chrono::duration<Rep, Period> &duration)
76 : mMutex{std::addressof(mutex)}
77 , mOwnsMutex{mMutex->try_lock_for(duration)}
83 UniqueLock(
const UniqueLock &) =
delete;
84 UniqueLock &operator=(
const UniqueLock &) =
delete;
86 UniqueLock(UniqueLock &&u)
noexcept;
87 UniqueLock &operator=(UniqueLock &&u)
noexcept;
93 template<
typename Clock,
typename Duration>
94 bool try_lock_until(
const std::chrono::time_point<Clock, Duration> &timePoint)
97 Q_ASSERT(!mOwnsMutex);
98 if (mMutex && !mOwnsMutex) {
99 mOwnsMutex = mMutex->try_lock_until(timePoint);
104 template<
typename Rep,
typename Period>
105 bool try_lock_for(
const std::chrono::duration<Rep, Period> &duration)
108 Q_ASSERT(!mOwnsMutex);
109 if (mMutex && !mOwnsMutex) {
110 mOwnsMutex = mMutex->try_lock_for(duration);
117 void swap(UniqueLock &u)
noexcept;
119 QMutex *release()
noexcept;
121 bool owns_lock()
const noexcept;
123 explicit operator bool()
const noexcept;
125 QMutex *mutex()
const noexcept;
A movable scoped lock type for QMutex.
Assume the calling thread has already obtained mutex ownership and manage it.
Do not acquire ownership of the mutex.
Try to acquire ownership of the mutex without blocking.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:50:12 by
doxygen 1.13.2 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.