summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-09-27 18:14:02 +0300
committerAndrei Karas <akaras@inbox.ru>2016-10-04 15:33:43 +0300
commitcb8ba63e65da87cc02371d79445f9b2aa50bc991 (patch)
tree762d403fbff56b1567732387e50c6a9fc9d7ee58
parentec54390f5659d01da337ce393b0ea5747716aeed (diff)
downloadhercules-cb8ba63e65da87cc02371d79445f9b2aa50bc991.tar.gz
hercules-cb8ba63e65da87cc02371d79445f9b2aa50bc991.tar.bz2
hercules-cb8ba63e65da87cc02371d79445f9b2aa50bc991.tar.xz
hercules-cb8ba63e65da87cc02371d79445f9b2aa50bc991.zip
Add missing checks into mutex.c
-rw-r--r--src/common/mutex.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/common/mutex.c b/src/common/mutex.c
index bdc2fb4dc..464a54161 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -24,6 +24,7 @@
#include "common/cbasetypes.h" // for WIN32
#include "common/memmgr.h"
+#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/timer.h"
@@ -84,6 +85,7 @@ struct mutex_data *mutex_create(void)
/// @copydoc mutex_interface::destroy()
void mutex_destroy(struct mutex_data *m)
{
+ nullpo_retv(m);
#ifdef WIN32
DeleteCriticalSection(&m->hMutex);
#else
@@ -96,6 +98,7 @@ void mutex_destroy(struct mutex_data *m)
/// @copydoc mutex_interface::lock()
void mutex_lock(struct mutex_data *m)
{
+ nullpo_retv(m);
#ifdef WIN32
EnterCriticalSection(&m->hMutex);
#else
@@ -106,6 +109,7 @@ void mutex_lock(struct mutex_data *m)
/// @copydoc mutex_interface::trylock()
bool mutex_trylock(struct mutex_data *m)
{
+ nullpo_retr(false, m);
#ifdef WIN32
if (TryEnterCriticalSection(&m->hMutex) != FALSE)
return true;
@@ -119,6 +123,7 @@ bool mutex_trylock(struct mutex_data *m)
/// @copydoc mutex_interface::unlock()
void mutex_unlock(struct mutex_data *m)
{
+ nullpo_retv(m);
#ifdef WIN32
LeaveCriticalSection(&m->hMutex);
#else
@@ -152,6 +157,7 @@ struct cond_data *cond_create(void)
/// @copydoc mutex_interface::cond_destroy()
void cond_destroy(struct cond_data *c)
{
+ nullpo_retv(c);
#ifdef WIN32
CloseHandle(c->events[EVENT_COND_SIGNAL]);
CloseHandle(c->events[EVENT_COND_BROADCAST]);
@@ -171,6 +177,7 @@ void cond_wait(struct cond_data *c, struct mutex_data *m, sysint timeout_ticks)
int result;
bool is_last = false;
+ nullpo_retv(c);
EnterCriticalSection(&c->waiters_lock);
c->nWaiters++;
LeaveCriticalSection(&c->waiters_lock);
@@ -201,6 +208,7 @@ void cond_wait(struct cond_data *c, struct mutex_data *m, sysint timeout_ticks)
mutex->lock(m);
#else
+ nullpo_retv(m);
if (timeout_ticks < 0) {
pthread_cond_wait(&c->hCond, &m->hMutex);
} else {
@@ -221,6 +229,7 @@ void cond_signal(struct cond_data *c)
#ifdef WIN32
# if 0
bool has_waiters = false;
+ nullpo_retv(c);
EnterCriticalSection(&c->waiters_lock);
if(c->nWaiters > 0)
has_waiters = true;
@@ -230,6 +239,7 @@ void cond_signal(struct cond_data *c)
# endif // 0
SetEvent(c->events[EVENT_COND_SIGNAL]);
#else
+ nullpo_retv(c);
pthread_cond_signal(&c->hCond);
#endif
}
@@ -240,6 +250,7 @@ void cond_broadcast(struct cond_data *c)
#ifdef WIN32
# if 0
bool has_waiters = false;
+ nullpo_retv(c);
EnterCriticalSection(&c->waiters_lock);
if(c->nWaiters > 0)
has_waiters = true;
@@ -249,6 +260,7 @@ void cond_broadcast(struct cond_data *c)
# endif // 0
SetEvent(c->events[EVENT_COND_BROADCAST]);
#else
+ nullpo_retv(c);
pthread_cond_broadcast(&c->hCond);
#endif
}