mutex.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (c) rAthena Project (www.rathena.org) - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _rA_MUTEX_H_
  4. #define _rA_MUTEX_H_
  5. typedef struct ramutex *ramutex; // Mutex
  6. typedef struct racond *racond; // Condition Var
  7. /**
  8. * Creates a Mutex
  9. *
  10. * @return not NULL
  11. */
  12. ramutex ramutex_create();
  13. /**
  14. * Destroys a Mutex
  15. *
  16. * @param m - the mutex to destroy
  17. */
  18. void ramutex_destroy( ramutex m );
  19. /**
  20. * Gets a lock
  21. *
  22. * @param m - the mutex to lock
  23. */
  24. void ramutex_lock( ramutex m);
  25. /**
  26. * Trys to get the Lock
  27. *
  28. * @param m - the mutex try to lock
  29. *
  30. * @return boolean (true = got the lock)
  31. */
  32. bool ramutex_trylock( ramutex m );
  33. /**
  34. * Unlocks a mutex
  35. *
  36. * @param m - the mutex to unlock
  37. */
  38. void ramutex_unlock( ramutex m);
  39. /**
  40. * Creates a Condition variable
  41. *
  42. * @return not NULL
  43. */
  44. racond racond_create();
  45. /**
  46. * Destroy a Condition variable
  47. *
  48. * @param c - the condition varaible to destroy
  49. */
  50. void racond_destroy( racond c );
  51. /**
  52. * Waits Until state is signalled
  53. *
  54. * @param c - the condition var to wait for signalled state
  55. * @param m - the mutex used for syncronization
  56. * @param timeout_ticks - timeout in ticks ( -1 = INFINITE )
  57. */
  58. void racond_wait( racond c, ramutex m, sysint timeout_ticks);
  59. /**
  60. * Sets the given condition var to signalled state
  61. *
  62. * @param c - condition var to set in signalled state.
  63. *
  64. * @note:
  65. * Only one waiter gets notified.
  66. */
  67. void racond_signal( racond c );
  68. /**
  69. * Sets notifys all waiting threads thats signalled.
  70. * @param c - condition var to set in signalled state
  71. *
  72. * @note:
  73. * All Waiters getting notified.
  74. */
  75. void racond_broadcast( racond c );
  76. #endif