summaryrefslogtreecommitdiff
path: root/src/common/mutex.h
diff options
context:
space:
mode:
authorblacksirius <blacksirius@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-06-10 02:27:07 +0000
committerblacksirius <blacksirius@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-06-10 02:27:07 +0000
commitcaa66e7c20a26859912c1efc3c5a00b8dafc0661 (patch)
treedcd528c3ec6c27c014fdb8e635e590cd2c4b5d6d /src/common/mutex.h
parentffaaae67cf0ce0569c894433c4ff213af707ea5a (diff)
downloadhercules-caa66e7c20a26859912c1efc3c5a00b8dafc0661.tar.gz
hercules-caa66e7c20a26859912c1efc3c5a00b8dafc0661.tar.bz2
hercules-caa66e7c20a26859912c1efc3c5a00b8dafc0661.tar.xz
hercules-caa66e7c20a26859912c1efc3c5a00b8dafc0661.zip
added mutex && cond var abstraction ( for pthread / winapi )
added type 'sysint' to cbasetypes, which's the width of the platform the release gets compiled for. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16256 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/mutex.h')
-rw-r--r--src/common/mutex.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/common/mutex.h b/src/common/mutex.h
new file mode 100644
index 000000000..4a32bcc8a
--- /dev/null
+++ b/src/common/mutex.h
@@ -0,0 +1,89 @@
+#ifndef _rA_MUTEX_H_
+#define _rA_MUTEX_H_
+
+
+typedef struct ramutex *ramutex; // Mutex
+typedef struct racond *racond; // Condition Var
+
+/**
+ * Creates a Mutex
+ *
+ * @return not NULL
+ */
+ramutex ramutex_create();
+
+/**
+ * Destroys a Mutex
+ *
+ * @param m - the mutex to destroy
+ */
+void ramutex_destroy( ramutex m );
+
+/**
+ * Gets a lock
+ *
+ * @param m - the mutex to lock
+ */
+void ramutex_lock( ramutex m);
+
+/**
+ * Trys to get the Lock
+ *
+ * @param m - the mutex try to lock
+ *
+ * @return boolean (true = got the lock)
+ */
+bool ramutex_trylock( ramutex m );
+
+/**
+ * Unlocks a mutex
+ *
+ * @param m - the mutex to unlock
+ */
+void ramutex_unlock( ramutex m);
+
+
+/**
+ * Creates a Condition variable
+ *
+ * @return not NULL
+ */
+racond racond_create();
+
+/**
+ * Destroy a Condition variable
+ *
+ * @param c - the condition varaible to destroy
+ */
+void racond_destroy( racond c );
+
+/**
+ * Waits Until state is signalled
+ *
+ * @param c - the condition var to wait for signalled state
+ * @param m - the mutex used for syncronization
+ * @param timeout_ticks - timeout in ticks ( -1 = INFINITE )
+ */
+void racond_wait( racond c, ramutex m, sysint timeout_ticks);
+
+/**
+ * Sets the given condition var to signalled state
+ *
+ * @param c - condition var to set in signalled state.
+ *
+ * @note:
+ * Only one waiter gets notified.
+ */
+void racond_signal( racond c );
+
+/**
+ * Sets notifys all waiting threads thats signalled.
+ * @param c - condition var to set in signalled state
+ *
+ * @note:
+ * All Waiters getting notified.
+ */
+void racond_broadcast( racond c );
+
+
+#endif