summaryrefslogtreecommitdiff
path: root/src/common/mutex.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-11-16 06:35:51 +0100
committerHaru <haru@dotalux.com>2014-11-16 07:16:23 +0100
commit02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f (patch)
tree3161fd5786bb563c32059068eb3b4876d2ae11ca /src/common/mutex.c
parent31bff051ee3c353fb7ee5e544d68feeaefd4941f (diff)
downloadhercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.tar.gz
hercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.tar.bz2
hercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.tar.xz
hercules-02fcaed6bd32b0ffbc4f03b8f9de6f0720e6253f.zip
Whitespace cleanup (no code changes)
This includes, and is not limited to: mixed or wrong indentation, excess whitespace (horizontal and vertical), misalignment, trailing spaces. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/mutex.c')
-rw-r--r--src/common/mutex.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/common/mutex.c b/src/common/mutex.c
index f046febf6..31202d440 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -52,19 +52,19 @@ struct racond{
ramutex *ramutex_create(void) {
struct ramutex *m;
-
+
m = (struct ramutex*)aMalloc( sizeof(struct ramutex) );
if (m == NULL) {
ShowFatalError("ramutex_create: OOM while allocating %"PRIuS" bytes.\n", sizeof(struct ramutex));
return NULL;
}
-
+
#ifdef WIN32
InitializeCriticalSection(&m->hMutex);
#else
pthread_mutex_init(&m->hMutex, NULL);
#endif
-
+
return m;
}//end: ramutex_create()
@@ -101,7 +101,7 @@ bool ramutex_trylock(ramutex *m) {
#else
if(pthread_mutex_trylock(&m->hMutex) == 0)
return true;
-
+
return false;
#endif
}//end: ramutex_trylock()
@@ -126,7 +126,7 @@ void ramutex_unlock(ramutex *m) {
racond *racond_create(void) {
struct racond *c;
-
+
c = (struct racond*)aMalloc( sizeof(struct racond) );
if (c == NULL) {
ShowFatalError("racond_create: OOM while allocating %"PRIuS" bytes\n", sizeof(struct racond));
@@ -135,13 +135,13 @@ racond *racond_create(void) {
#ifdef WIN32
c->nWaiters = 0;
- c->events[ EVENT_COND_SIGNAL ] = CreateEvent( NULL, FALSE, FALSE, NULL );
- c->events[ EVENT_COND_BROADCAST ] = CreateEvent( NULL, TRUE, FALSE, NULL );
+ c->events[EVENT_COND_SIGNAL] = CreateEvent(NULL, FALSE, FALSE, NULL);
+ c->events[EVENT_COND_BROADCAST] = CreateEvent(NULL, TRUE, FALSE, NULL);
InitializeCriticalSection( &c->waiters_lock );
#else
pthread_cond_init(&c->hCond, NULL);
#endif
-
+
return c;
}//end: racond_create()
@@ -174,24 +174,20 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
ms = INFINITE;
else
ms = (timeout_ticks > MAXDWORD) ? (MAXDWORD - 1) : (DWORD)timeout_ticks;
-
-
+
// we can release the mutex (m) here, cause win's
// manual reset events maintain state when used with
// SetEvent()
ramutex_unlock(m);
result = WaitForMultipleObjects(2, c->events, FALSE, ms);
-
-
+
EnterCriticalSection(&c->waiters_lock);
c->nWaiters--;
if( (result == WAIT_OBJECT_0 + EVENT_COND_BROADCAST) && (c->nWaiters == 0) )
is_last = true; // Broadcast called!
LeaveCriticalSection(&c->waiters_lock);
-
-
// we are the last waiter that has to be notified, or to stop waiting
// so we have to do a manual reset
if(is_last == true)
@@ -206,10 +202,10 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
}else{
struct timespec wtime;
int64 exact_timeout = timer->gettick() + timeout_ticks;
-
+
wtime.tv_sec = exact_timeout/1000;
wtime.tv_nsec = (exact_timeout%1000)*1000000;
-
+
pthread_cond_timedwait( &c->hCond, &m->hMutex, &wtime);
}
@@ -219,13 +215,15 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
void racond_signal(racond *c) {
#ifdef WIN32
-// bool has_waiters = false;
-// EnterCriticalSection(&c->waiters_lock);
-// if(c->nWaiters > 0)
-// has_waiters = true;
-// LeaveCriticalSection(&c->waiters_lock);
-
-// if(has_waiters == true)
+# if 0
+ bool has_waiters = false;
+ EnterCriticalSection(&c->waiters_lock);
+ if(c->nWaiters > 0)
+ has_waiters = true;
+ LeaveCriticalSection(&c->waiters_lock);
+
+ if(has_waiters == true)
+# endif // 0
SetEvent( c->events[ EVENT_COND_SIGNAL ] );
#else
pthread_cond_signal(&c->hCond);
@@ -235,13 +233,15 @@ void racond_signal(racond *c) {
void racond_broadcast(racond *c) {
#ifdef WIN32
-// bool has_waiters = false;
-// EnterCriticalSection(&c->waiters_lock);
-// if(c->nWaiters > 0)
-// has_waiters = true;
-// LeaveCriticalSection(&c->waiters_lock);
-
-// if(has_waiters == true)
+# if 0
+ bool has_waiters = false;
+ EnterCriticalSection(&c->waiters_lock);
+ if(c->nWaiters > 0)
+ has_waiters = true;
+ LeaveCriticalSection(&c->waiters_lock);
+
+ if(has_waiters == true)
+# endif // 0
SetEvent( c->events[ EVENT_COND_BROADCAST ] );
#else
pthread_cond_broadcast(&c->hCond);