Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcos_semaphore.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*=============================================================================
  26. VideoCore OS Abstraction Layer - public header file
  27. =============================================================================*/
  28. #ifndef VCOS_SEMAPHORE_H
  29. #define VCOS_SEMAPHORE_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #include "vcos_types.h"
  34. #ifndef VCOS_PLATFORM_H
  35. #include "pthreads/vcos_platform.h"
  36. #endif
  37. /**
  38. * \file vcos_semaphore.h
  39. *
  40. * \section sem Semaphores
  41. *
  42. * This provides counting semaphores. Semaphores are not re-entrant. On sensible
  43. * operating systems a semaphore can always be posted but can only be taken in
  44. * thread (not interrupt) context. Under Nucleus, a LISR cannot post a semaphore,
  45. * although it would not be hard to lift this restriction.
  46. *
  47. * \subsection timeout Timeout
  48. *
  49. * On both Nucleus and ThreadX a semaphore can be taken with a timeout. This is
  50. * not supported by VCOS because it makes the non-timeout code considerably more
  51. * complicated (and hence slower). In the unlikely event that you need a timeout
  52. * with a semaphore, and you cannot simply redesign your code to avoid it, use
  53. * an event flag (vcos_event_flags.h).
  54. *
  55. * \subsection sem_nucleus Changes from Nucleus:
  56. *
  57. * Semaphores are always "FIFO" - i.e. sleeping threads are woken in FIFO order. That's
  58. * because:
  59. * \arg there's no support for NU_PRIORITY in threadx (though it can be emulated, slowly)
  60. * \arg we don't appear to actually consciously use it - for example, Dispmanx uses
  61. * it, but all threads waiting are the same priority.
  62. *
  63. */
  64. /**
  65. * \brief Create a semaphore.
  66. *
  67. * Create a semaphore.
  68. *
  69. * @param sem Pointer to memory to be initialized
  70. * @param name A name for this semaphore. The name may be truncated internally.
  71. * @param count The initial count for the semaphore.
  72. *
  73. * @return VCOS_SUCCESS if the semaphore was created.
  74. *
  75. */
  76. VCOS_INLINE_DECL
  77. VCOS_STATUS_T vcos_semaphore_create(VCOS_SEMAPHORE_T *sem, const char *name, VCOS_UNSIGNED count);
  78. /**
  79. * \brief Wait on a semaphore.
  80. *
  81. * There is no timeout option on a semaphore, as adding this will slow down
  82. * implementations on some platforms. If you need that kind of behaviour, use
  83. * an event group.
  84. *
  85. * On most platforms this always returns VCOS_SUCCESS, and so would ideally be
  86. * a void function, however some platforms allow a wait to be interrupted so
  87. * it remains non-void.
  88. *
  89. * @param sem Semaphore to wait on
  90. * @return VCOS_SUCCESS - semaphore was taken.
  91. * VCOS_EAGAIN - could not take semaphore
  92. *
  93. */
  94. VCOS_INLINE_DECL
  95. VCOS_STATUS_T vcos_semaphore_wait(VCOS_SEMAPHORE_T *sem);
  96. /**
  97. * \brief Wait on a semaphore with a timeout.
  98. *
  99. * Note that this function may not be implemented on all
  100. * platforms, and may not be efficient on all platforms
  101. * (see comment in vcos_semaphore_wait)
  102. *
  103. * Try to obtain the semaphore. If it is already taken, return
  104. * VCOS_EAGAIN.
  105. * @param sem Semaphore to wait on
  106. * @param timeout Number of milliseconds to wait before
  107. * returning if the semaphore can't be acquired.
  108. * @return VCOS_SUCCESS - semaphore was taken.
  109. * VCOS_EAGAIN - could not take semaphore (i.e. timeout
  110. * expired)
  111. * VCOS_EINVAL - Some other error (most likely bad
  112. * parameters).
  113. */
  114. VCOS_INLINE_DECL
  115. VCOS_STATUS_T vcos_semaphore_wait_timeout(VCOS_SEMAPHORE_T *sem, VCOS_UNSIGNED timeout);
  116. /**
  117. * \brief Try to wait for a semaphore.
  118. *
  119. * Try to obtain the semaphore. If it is already taken, return VCOS_TIMEOUT.
  120. * @param sem Semaphore to wait on
  121. * @return VCOS_SUCCESS - semaphore was taken.
  122. * VCOS_EAGAIN - could not take semaphore
  123. */
  124. VCOS_INLINE_DECL
  125. VCOS_STATUS_T vcos_semaphore_trywait(VCOS_SEMAPHORE_T *sem);
  126. /**
  127. * \brief Post a semaphore.
  128. *
  129. * @param sem Semaphore to wait on
  130. */
  131. VCOS_INLINE_DECL
  132. VCOS_STATUS_T vcos_semaphore_post(VCOS_SEMAPHORE_T *sem);
  133. /**
  134. * \brief Delete a semaphore, releasing any resources consumed by it.
  135. *
  136. * @param sem Semaphore to wait on
  137. */
  138. VCOS_INLINE_DECL
  139. void vcos_semaphore_delete(VCOS_SEMAPHORE_T *sem);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif