From ae0cc2ec61c75ddd5b22e27e1cecc806a32feee5 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Sun, 16 May 2021 15:45:38 +0900 Subject: [PATCH] waste removal Signed-off-by: tomoaki e --- MQTTSNGateway/src/linux/Threading.cpp | 39 +++++++++++---------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/MQTTSNGateway/src/linux/Threading.cpp b/MQTTSNGateway/src/linux/Threading.cpp index 4341034..703dd19 100644 --- a/MQTTSNGateway/src/linux/Threading.cpp +++ b/MQTTSNGateway/src/linux/Threading.cpp @@ -121,44 +121,37 @@ Mutex::~Mutex(void) void Mutex::lock(void) { + int rc = 0; if (_pmutex) { - pthread_mutex_lock(_pmutex); + rc = pthread_mutex_lock(_pmutex); } else { - try - { - if (pthread_mutex_lock(&_mutex)) - { - throw Exception("Mutex lock error", errno); - } - } catch (char* errmsg) - { - throw Exception("The same thread can't acquire a mutex twice", errno); - } + rc = pthread_mutex_lock(&_mutex); + } + + if (rc) + { + throw Exception("Mutex lock error", errno); } } void Mutex::unlock(void) { - + int rc = 0; if (_pmutex) { - pthread_mutex_unlock(_pmutex); + rc = pthread_mutex_unlock(_pmutex); } else { - try - { - if (pthread_mutex_unlock(&_mutex)) - { - throw Exception("Mutex unlock error", errno); - } - } catch (char* errmsg) - { - throw Exception("Mutex can't unlock.", -1); - } + rc = pthread_mutex_unlock(&_mutex); + } + + if (rc) + { + throw Exception("Mutex lock error", errno); } }