osip_mt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
  3. Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #ifndef _OSIP_MT_H_
  17. #define _OSIP_MT_H_
  18. #ifndef OSIP_MONOTHREAD
  19. #include <stdio.h>
  20. /**
  21. * @file osip_mt.h
  22. * @brief oSIP Thread, Mutex and Semaphore definitions
  23. *
  24. * Those methods are only available if the library is compile
  25. * in multi threaded mode. This is the default for oSIP.
  26. */
  27. /**
  28. * @defgroup oSIP_THREAD oSIP Thread Routines
  29. * @ingroup osip2_port
  30. * @{
  31. */
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**
  36. * Structure for referencing a thread
  37. * @struct osip_thread
  38. */
  39. struct osip_thread;
  40. /**
  41. * Allocate (or initialise if a thread address is given)
  42. * @param stacksize The stack size of the thread. (20000 is a good value)
  43. * @param func The method where the thread start.
  44. * @param arg A pointer on the argument given to the method 'func'.
  45. */
  46. struct osip_thread *osip_thread_create(int stacksize, void *(*func)(void *), void *arg);
  47. /**
  48. * Join a thread.
  49. * @param thread The thread to join.
  50. */
  51. int osip_thread_join(struct osip_thread *thread);
  52. /**
  53. * Set the priority of a thread. (NOT IMPLEMENTED ON ALL SYSTEMS)
  54. * @param thread The thread to work on.
  55. * @param priority The priority value to set.
  56. */
  57. int osip_thread_set_priority(struct osip_thread *thread, int priority);
  58. /**
  59. * Exit from a thread.
  60. */
  61. void osip_thread_exit(void);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. /** @}
  66. * @defgroup oSIP_SEMA oSIP semaphore definitions
  67. * @ingroup osip2_port
  68. * @{
  69. */
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. /**
  74. * Structure for referencing a semaphore element.
  75. * @struct osip_sem
  76. */
  77. struct osip_sem;
  78. /**
  79. * Allocate and Initialise a semaphore.
  80. * @param value The initial value for the semaphore.
  81. */
  82. struct osip_sem *osip_sem_init(unsigned int value);
  83. /**
  84. * Destroy a semaphore.
  85. * @param sem The semaphore to destroy.
  86. */
  87. int osip_sem_destroy(struct osip_sem *sem);
  88. /**
  89. * Post operation on a semaphore.
  90. * @param sem The semaphore to destroy.
  91. */
  92. int osip_sem_post(struct osip_sem *sem);
  93. /**
  94. * Wait operation on a semaphore.
  95. * NOTE: this call will block if the semaphore is at 0.
  96. * @param sem The semaphore to destroy.
  97. */
  98. int osip_sem_wait(struct osip_sem *sem);
  99. /**
  100. * Wait operation on a semaphore.
  101. * NOTE: if the semaphore is at 0, this call won't block.
  102. * @param sem The semaphore to destroy.
  103. */
  104. int osip_sem_trywait(struct osip_sem *sem);
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. /** @}
  109. * @defgroup oSIP_MUTEX oSIP mutex definitions
  110. * @ingroup osip2_port
  111. * @{
  112. */
  113. #ifdef __cplusplus
  114. extern "C" {
  115. #endif
  116. /**
  117. * Structure for referencing a mutex element.
  118. * @struct osip_mutex
  119. */
  120. struct osip_mutex;
  121. /**
  122. * Allocate and Initialise a mutex.
  123. */
  124. struct osip_mutex *osip_mutex_init(void);
  125. /**
  126. * Destroy the mutex.
  127. * @param mut The mutex to destroy.
  128. */
  129. void osip_mutex_destroy(struct osip_mutex *mut);
  130. /**
  131. * Lock the mutex.
  132. * @param mut The mutex to lock.
  133. */
  134. int osip_mutex_lock(struct osip_mutex *mut);
  135. /**
  136. * Unlock the mutex.
  137. * @param mut The mutex to unlock.
  138. */
  139. int osip_mutex_unlock(struct osip_mutex *mut);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. /** @} */
  144. #endif /* OSIP_MONOTHREAD */
  145. #endif /* end of _THREAD_H_ */