mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-15 08:26:51 +01:00
@@ -121,44 +121,37 @@ Mutex::~Mutex(void)
|
|||||||
|
|
||||||
void Mutex::lock(void)
|
void Mutex::lock(void)
|
||||||
{
|
{
|
||||||
|
int rc = 0;
|
||||||
if (_pmutex)
|
if (_pmutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(_pmutex);
|
rc = pthread_mutex_lock(_pmutex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
rc = pthread_mutex_lock(&_mutex);
|
||||||
{
|
}
|
||||||
if (pthread_mutex_lock(&_mutex))
|
|
||||||
{
|
if (rc)
|
||||||
throw Exception("Mutex lock error", errno);
|
{
|
||||||
}
|
throw Exception("Mutex lock error", errno);
|
||||||
} catch (char* errmsg)
|
|
||||||
{
|
|
||||||
throw Exception("The same thread can't acquire a mutex twice", errno);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mutex::unlock(void)
|
void Mutex::unlock(void)
|
||||||
{
|
{
|
||||||
|
int rc = 0;
|
||||||
if (_pmutex)
|
if (_pmutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(_pmutex);
|
rc = pthread_mutex_unlock(_pmutex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
rc = pthread_mutex_unlock(&_mutex);
|
||||||
{
|
}
|
||||||
if (pthread_mutex_unlock(&_mutex))
|
|
||||||
{
|
if (rc)
|
||||||
throw Exception("Mutex unlock error", errno);
|
{
|
||||||
}
|
throw Exception("Mutex lock error", errno);
|
||||||
} catch (char* errmsg)
|
|
||||||
{
|
|
||||||
throw Exception("Mutex can't unlock.", -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user