From c28204066c2d3bae989132ab15e8df437ae38f3d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 2 Aug 2012 16:15:22 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/thread/qmutex_linux.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/thread/qmutex_linux.cpp') diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index a10bd35eff..3ccaeff4e3 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -87,7 +87,7 @@ static inline int futexFlags() return value; } -static inline int _q_futex(void *addr, int op, int val, const struct timespec *timeout) +static inline int _q_futex(void *addr, int op, int val, const struct timespec *timeout) Q_DECL_NOTHROW { volatile int *int_addr = reinterpret_cast(addr); #if Q_BYTE_ORDER == Q_BIG_ENDIAN && QT_POINTER_SIZE == 8 @@ -106,7 +106,7 @@ static inline QMutexData *dummyFutexValue() return reinterpret_cast(quintptr(3)); } -bool QBasicMutex::lockInternal(int timeout) +bool QBasicMutex::lockInternal(int timeout) Q_DECL_NOTHROW { QElapsedTimer elapsedTimer; if (timeout >= 1) @@ -147,7 +147,7 @@ bool QBasicMutex::lockInternal(int timeout) return true; } -void QBasicMutex::unlockInternal() +void QBasicMutex::unlockInternal() Q_DECL_NOTHROW { QMutexData *d = d_ptr.load(); Q_ASSERT(d); //we must be locked -- cgit v1.2.3