From 909b9d35ff9bdaaac784cf88f669eea0982fdd58 Mon Sep 17 00:00:00 2001 From: hemagx Date: Wed, 17 Feb 2016 15:29:36 +0200 Subject: Interface mutex.c --- src/common/mutex.h | 152 ++++++++++++++++++++++++++++------------------------- 1 file changed, 80 insertions(+), 72 deletions(-) (limited to 'src/common/mutex.h') diff --git a/src/common/mutex.h b/src/common/mutex.h index e49791493..54e304add 100644 --- a/src/common/mutex.h +++ b/src/common/mutex.h @@ -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 @@ -21,91 +21,99 @@ #ifndef COMMON_MUTEX_H #define COMMON_MUTEX_H -#include "common/cbasetypes.h" +#include "common/hercules.h" typedef struct ramutex ramutex; // Mutex typedef struct racond racond; // Condition Var -#ifdef HERCULES_CORE -/** - * Creates a Mutex - * - * @return not NULL - */ -ramutex *ramutex_create(void); +struct mutex_interface { + /** + * Creates a Mutex + * + * @return The created mutex. + */ + ramutex *(*create) (void); -/** - * Destroys a Mutex - * - * @param m - the mutex to destroy - */ -void ramutex_destroy(ramutex *m); + /** + * Destroys a Mutex. + * + * @param m the mutex to destroy. + */ + void (*destroy) (ramutex *m); -/** - * Gets a lock - * - * @param m - the mutex to lock - */ -void ramutex_lock(ramutex *m); + /** + * Gets a lock. + * + * @param m The mutex to lock. + */ + void (*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); + /** + * Tries to get a lock. + * + * @param m The mutex to try to lock. + * @return success status. + * @retval true if the lock was acquired. + * @retval false if the mutex couldn't be locked. + */ + bool (*trylock) (ramutex *m); -/** - * Unlocks a mutex - * - * @param m - the mutex to unlock - */ -void ramutex_unlock(ramutex *m); + /** + * Unlocks a mutex. + * + * @param m The mutex to unlock. + */ + void (*unlock) (ramutex *m); -/** - * Creates a Condition variable - * - * @return not NULL - */ -racond *racond_create(void); + /** + * Creates a Condition variable. + * + * @return the created condition variable. + */ + racond *(*cond_create) (void); -/** - * Destroy a Condition variable - * - * @param c - the condition variable to destroy - */ -void racond_destroy(racond *c); + /** + * Destroys a Condition variable. + * + * @param c the condition variable to destroy. + */ + void (*cond_destroy) (racond *c); -/** - * Waits Until state is signaled - * - * @param c - the condition var to wait for signaled state - * @param m - the mutex used for synchronization - * @param timeout_ticks - timeout in ticks ( -1 = INFINITE ) - */ -void racond_wait(racond *c, ramutex *m, sysint timeout_ticks); + /** + * Waits Until state is signaled. + * + * @param c The condition var to wait for signaled state. + * @param m The mutex used for synchronization. + * @param timeout_ticks Timeout in ticks (-1 = INFINITE) + */ + void (*cond_wait) (racond *c, ramutex *m, sysint timeout_ticks); -/** - * Sets the given condition var to signaled state - * - * @param c - condition var to set in signaled state. - * - * @note: - * Only one waiter gets notified. - */ -void racond_signal(racond *c); + /** + * Sets the given condition var to signaled state. + * + * @remark + * Only one waiter gets notified. + * + * @param c Condition var to set in signaled state. + */ + void (*cond_signal) (racond *c); -/** - * Sets notifies all waiting threads thats signaled. - * @param c - condition var to set in signaled state - * - * @note: - * All Waiters getting notified. - */ -void racond_broadcast(racond *c); + /** + * Sets notifies all waiting threads thats signaled. + * + * @remark + * All Waiters getting notified. + * + * @param c Condition var to set in signaled state. + */ + void (*cond_broadcast) (racond *c); +}; + +#ifdef HERCULES_CORE +void mutex_defaults(void); #endif // HERCULES_CORE +HPShared struct mutex_interface *mutex; + #endif /* COMMON_MUTEX_H */ -- cgit v1.2.3-60-g2f50