diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-08-02 16:15:22 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-25 10:35:26 +0200 |
commit | c28204066c2d3bae989132ab15e8df437ae38f3d (patch) | |
tree | 989935de1629ae724d8826f16244e85907ad7043 /src/corelib/thread/qmutex_p.h | |
parent | 98437f0e2edde7f5e49e1a6bea27ef130b58bee4 (diff) |
Mark mutex locking and unlocking functions with noexcept
Unlocking a mutex can never throw an exception. That doesn't make
sense and our code should make sure it can't happen. Right now,
provided that the system-level functions don't throw, we don't either.
Locking a mutex cannot throw on Linux because we use futexes
directly. A non-recursive mutex is just a futex, whereas a recursive
mutex uses a mutex (a futex) to manage a lock count.
However, on other platforms, due to the freelist, there can be memory
allocation, which means it might throw std::bad_alloc. Not because of
the freelist itself (that uses malloc and will just crash if malloc
fails) but because of Q_GLOBAL_STATIC. In 5.1, the global static will
be noexcept provided the type's constructor is so too (it is, in this
case).
Change-Id: I4c562383f48de1be7827b9afb512d73eaf0792d5
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qmutex_p.h')
-rw-r--r-- | src/corelib/thread/qmutex_p.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/thread/qmutex_p.h b/src/corelib/thread/qmutex_p.h index 92f13b1b7d..3ef99d5fc0 100644 --- a/src/corelib/thread/qmutex_p.h +++ b/src/corelib/thread/qmutex_p.h @@ -86,7 +86,7 @@ public: QMutexPrivate(); bool wait(int timeout = -1); - void wakeUp(); + void wakeUp() Q_DECL_NOTHROW; // Conrol the lifetime of the privates QAtomicInt refCount; @@ -115,7 +115,7 @@ public: QAtomicInt waiters; //number of thread waiting QAtomicInt possiblyUnlocked; //bool saying that a timed wait timed out enum { BigNumber = 0x100000 }; //Must be bigger than the possible number of waiters (number of threads) - void derefWaiters(int value); + void derefWaiters(int value) Q_DECL_NOTHROW; //platform specific stuff #if defined(Q_OS_MAC) @@ -139,8 +139,8 @@ public: uint count; QMutex mutex; - bool lock(int timeout); - void unlock(); + bool lock(int timeout) QT_MUTEX_LOCK_NOEXCEPT; + void unlock() Q_DECL_NOTHROW; }; QT_END_NAMESPACE |