diff options
| author | Marc Mutz <[email protected]> | 2025-06-23 11:32:04 +0200 |
|---|---|---|
| committer | Marc Mutz <[email protected]> | 2025-06-26 06:16:31 +0200 |
| commit | 40b13755c414d9eb8abeeabbe44f88e24932af28 (patch) | |
| tree | 718949b0a2507016c6480ce6e51a8342cf50dfe0 /src | |
| parent | 56709e812c2ebb3d7f942508947ac7b0394d71ce (diff) | |
QLockFile: inline old int-based timeout functions
The chrono-first approach asks that potentially-truncating functions
that convert from chrono to int be inlined, so the UB happens in the
user's domain and not in Qt's.
When 0592123a0c68b65c83555dc0f023c4bc77030f31 added the functions for
6.2, this approach wasn't, yet, agreed upon, so catch the code up now.
Found in independent review.
As a drive-by, fix incorrect inner spaces on a {} constructor call,
amending 5cea5fc80b9e1b19d620ec6be1acd5cdbd220971.
Pick-to: 6.10
Change-Id: Ic231af1f8c8e10868b7fa9b1f09a63eb8478da0a
Reviewed-by: David Faure <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/compat/removed_api.cpp | 2 | ||||
| -rw-r--r-- | src/corelib/io/qlockfile.cpp | 18 | ||||
| -rw-r--r-- | src/corelib/io/qlockfile.h | 20 |
3 files changed, 28 insertions, 12 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 8260d50fd3a..5b592bcfc76 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -1454,6 +1454,8 @@ void QFutureInterfaceBase::setContinuation(std::function<void(const QFutureInter } #endif // QT_CONFIG(future) +#include "qlockfile.h" // inlined API + #include "qlogging.h" QNoDebug QMessageLogger::noDebug() const noexcept diff --git a/src/corelib/io/qlockfile.cpp b/src/corelib/io/qlockfile.cpp index a15549217a0..e4dd74152a2 100644 --- a/src/corelib/io/qlockfile.cpp +++ b/src/corelib/io/qlockfile.cpp @@ -126,6 +126,8 @@ QString QLockFile::fileName() const } /*! + \fn void QLockFile::setStaleLockTime(int staleLockTime) + Sets \a staleLockTime to be the time in milliseconds after which a lock file is considered stale. The default value is 30000, i.e. 30 seconds. @@ -146,10 +148,6 @@ QString QLockFile::fileName() const \sa staleLockTime() */ -void QLockFile::setStaleLockTime(int staleLockTime) -{ - setStaleLockTime(std::chrono::milliseconds{staleLockTime}); -} /*! \since 6.2 @@ -176,15 +174,13 @@ void QLockFile::setStaleLockTime(std::chrono::milliseconds staleLockTime) } /*! + \fn int QLockFile::staleLockTime() const + Returns the time in milliseconds after which a lock file is considered stale. \sa setStaleLockTime() */ -int QLockFile::staleLockTime() const -{ - return int(staleLockTimeAsDuration().count()); -} /*! \fn std::chrono::milliseconds QLockFile::staleLockTimeAsDuration() const \overload @@ -234,6 +230,8 @@ bool QLockFile::lock() } /*! + \fn bool QLockFile::tryLock(int timeout) + Attempts to create the lock file. This function returns \c true if the lock was obtained; otherwise it returns \c false. If another process (or another thread) has created the lock file already, this function will @@ -253,10 +251,6 @@ bool QLockFile::lock() \sa lock(), unlock() */ -bool QLockFile::tryLock(int timeout) -{ - return tryLock(std::chrono::milliseconds{ timeout }); -} /*! \overload diff --git a/src/corelib/io/qlockfile.h b/src/corelib/io/qlockfile.h index ca1885a7819..6b7b28c6bbc 100644 --- a/src/corelib/io/qlockfile.h +++ b/src/corelib/io/qlockfile.h @@ -22,10 +22,13 @@ public: QString fileName() const; bool lock(); + QT_CORE_INLINE_SINCE(6, 10) bool tryLock(int timeout); void unlock(); + QT_CORE_INLINE_SINCE(6, 10) void setStaleLockTime(int); + QT_CORE_INLINE_SINCE(6, 10) int staleLockTime() const; bool tryLock(std::chrono::milliseconds timeout = std::chrono::milliseconds::zero()); @@ -53,6 +56,23 @@ private: Q_DISABLE_COPY(QLockFile) }; +#if QT_CORE_INLINE_IMPL_SINCE(6, 10) +bool QLockFile::tryLock(int timeout) +{ + return tryLock(std::chrono::milliseconds{timeout}); +} + +void QLockFile::setStaleLockTime(int staleLockTime) +{ + setStaleLockTime(std::chrono::milliseconds{staleLockTime}); +} + +int QLockFile::staleLockTime() const +{ + return int(staleLockTimeAsDuration().count()); +} +#endif // QT_CORE_INLINE_IMPL_SINCE(6, 10) + QT_END_NAMESPACE #endif // QLOCKFILE_H |
