chcond.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS 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
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /*
  16. Concepts and parts of this file have been contributed by Leon Woestenberg.
  17. */
  18. /**
  19. * @file chcond.h
  20. * @brief Condition Variables macros and structures.
  21. *
  22. * @addtogroup condvars
  23. * @{
  24. */
  25. #ifndef CHCOND_H
  26. #define CHCOND_H
  27. #if (CH_CFG_USE_CONDVARS == TRUE) || defined(__DOXYGEN__)
  28. /*===========================================================================*/
  29. /* Module constants. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Module pre-compile time settings. */
  33. /*===========================================================================*/
  34. /*===========================================================================*/
  35. /* Derived constants and error checks. */
  36. /*===========================================================================*/
  37. #if CH_CFG_USE_MUTEXES == FALSE
  38. #error "CH_CFG_USE_CONDVARS requires CH_CFG_USE_MUTEXES"
  39. #endif
  40. /*===========================================================================*/
  41. /* Module data structures and types. */
  42. /*===========================================================================*/
  43. /**
  44. * @brief condition_variable_t structure.
  45. */
  46. typedef struct condition_variable {
  47. threads_queue_t queue; /**< @brief Condition variable
  48. threads queue. */
  49. } condition_variable_t;
  50. /*===========================================================================*/
  51. /* Module macros. */
  52. /*===========================================================================*/
  53. /**
  54. * @brief Data part of a static condition variable initializer.
  55. * @details This macro should be used when statically initializing a condition
  56. * variable that is part of a bigger structure.
  57. *
  58. * @param[in] name the name of the condition variable
  59. */
  60. #define _CONDVAR_DATA(name) {_THREADS_QUEUE_DATA(name.queue)}
  61. /**
  62. * @brief Static condition variable initializer.
  63. * @details Statically initialized condition variables require no explicit
  64. * initialization using @p chCondInit().
  65. *
  66. * @param[in] name the name of the condition variable
  67. */
  68. #define CONDVAR_DECL(name) condition_variable_t name = _CONDVAR_DATA(name)
  69. /*===========================================================================*/
  70. /* External declarations. */
  71. /*===========================================================================*/
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75. void chCondObjectInit(condition_variable_t *cp);
  76. void chCondSignal(condition_variable_t *cp);
  77. void chCondSignalI(condition_variable_t *cp);
  78. void chCondBroadcast(condition_variable_t *cp);
  79. void chCondBroadcastI(condition_variable_t *cp);
  80. msg_t chCondWait(condition_variable_t *cp);
  81. msg_t chCondWaitS(condition_variable_t *cp);
  82. #if CH_CFG_USE_CONDVARS_TIMEOUT == TRUE
  83. msg_t chCondWaitTimeout(condition_variable_t *cp, sysinterval_t timeout);
  84. msg_t chCondWaitTimeoutS(condition_variable_t *cp, sysinterval_t timeout);
  85. #endif
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. /*===========================================================================*/
  90. /* Module inline functions. */
  91. /*===========================================================================*/
  92. #endif /* CH_CFG_USE_CONDVARS == TRUE */
  93. #endif /* CHCOND_H */
  94. /** @} */