mutex.h 1.5 KB

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