1 /* 2 * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /* 8 * @file condition.h 9 * @brief Condition variable for libmetal. 10 */ 11 12 #ifndef __METAL_CONDITION__H__ 13 #define __METAL_CONDITION__H__ 14 15 #include <metal/mutex.h> 16 #include <metal/utilities.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 /** \defgroup condition Condition Variable Interfaces 23 * @{ 24 */ 25 26 /** Opaque libmetal condition variable data structure. */ 27 struct metal_condition; 28 29 /** 30 * @brief Initialize a libmetal condition variable. 31 * @param[in] cv condition variable to initialize. 32 */ 33 static inline void metal_condition_init(struct metal_condition *cv); 34 35 /** 36 * @brief Notify one waiter. 37 * Before calling this function, the caller 38 * should have acquired the mutex. 39 * @param[in] cv condition variable 40 * @return zero on no errors, non-zero on errors 41 * @see metal_condition_wait, metal_condition_broadcast 42 */ 43 static inline int metal_condition_signal(struct metal_condition *cv); 44 45 /** 46 * @brief Notify all waiters. 47 * Before calling this function, the caller 48 * should have acquired the mutex. 49 * @param[in] cv condition variable 50 * @return zero on no errors, non-zero on errors 51 * @see metal_condition_wait, metal_condition_signal 52 */ 53 static inline int metal_condition_broadcast(struct metal_condition *cv); 54 55 /** 56 * @brief Block until the condition variable is notified. 57 * Before calling this function, the caller should 58 * have acquired the mutex. 59 * @param[in] cv condition variable 60 * @param[in] m mutex 61 * @return 0 on success, non-zero on failure. 62 * @see metal_condition_signal 63 */ 64 int metal_condition_wait(struct metal_condition *cv, metal_mutex_t *m); 65 66 /** @} */ 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #include <metal/system/@PROJECT_SYSTEM@/condition.h> 73 74 #endif /* __METAL_CONDITION__H__ */ 75