summaryrefslogtreecommitdiff
path: root/src/common/mutex.c
diff options
context:
space:
mode:
authorhemagx <hemagx2@gmail.com>2016-02-17 15:29:36 +0200
committerHaru <haru@dotalux.com>2016-07-12 20:58:36 +0200
commit909b9d35ff9bdaaac784cf88f669eea0982fdd58 (patch)
treeab82dbcd0b448f20e3787cf2e5f34758327f7e1e /src/common/mutex.c
parent591e877c7f30d4c9d34b996f245b0ad0ee81c46d (diff)
downloadhercules-909b9d35ff9bdaaac784cf88f669eea0982fdd58.tar.gz
hercules-909b9d35ff9bdaaac784cf88f669eea0982fdd58.tar.bz2
hercules-909b9d35ff9bdaaac784cf88f669eea0982fdd58.tar.xz
hercules-909b9d35ff9bdaaac784cf88f669eea0982fdd58.zip
Interface mutex.c
Diffstat (limited to 'src/common/mutex.c')
-rw-r--r--src/common/mutex.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/common/mutex.c b/src/common/mutex.c
index 0f02b153f..15c0c5101 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) rAthena Project (www.rathena.org)
*
* Hercules is free software: you can redistribute it and/or modify
@@ -34,6 +34,9 @@
#include <sys/time.h>
#endif
+struct mutex_interface mutex_s;
+struct mutex_interface *mutex;
+
struct ramutex{
#ifdef WIN32
CRITICAL_SECTION hMutex;
@@ -181,7 +184,7 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
// we can release the mutex (m) here, cause win's
// manual reset events maintain state when used with
// SetEvent()
- ramutex_unlock(m);
+ mutex->unlock(m);
result = WaitForMultipleObjects(2, c->events, FALSE, ms);
@@ -196,7 +199,7 @@ void racond_wait(racond *c, ramutex *m, sysint timeout_ticks) {
if(is_last == true)
ResetEvent( c->events[EVENT_COND_BROADCAST] );
- ramutex_lock(m);
+ mutex->lock(m);
#else
if(timeout_ticks < 0){
@@ -247,3 +250,19 @@ void racond_broadcast(racond *c) {
pthread_cond_broadcast(&c->hCond);
#endif
}//end: racond_broadcast()
+
+void mutex_defaults(void)
+{
+ mutex = &mutex_s;
+ mutex->create = ramutex_create;
+ mutex->destroy = ramutex_destroy;
+ mutex->lock = ramutex_lock;
+ mutex->trylock = ramutex_trylock;
+ mutex->unlock = ramutex_unlock;
+
+ mutex->cond_create = racond_create;
+ mutex->cond_destroy = racond_destroy;
+ mutex->cond_wait = racond_wait;
+ mutex->cond_signal = racond_signal;
+ mutex->cond_broadcast = racond_broadcast;
+}