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 /** Opaque libmetal condition variable data structure. */ 26 struct metal_condition; 27 28 /** 29 * @brief Initialize a libmetal condition variable. 30 * @param[in] cv condition variable to initialize. 31 */ 32 static inline void metal_condition_init(struct metal_condition *cv); 33 34 /** 35 * @brief Notify one waiter. 36 * Before calling this function, the caller 37 * should have acquired the mutex. 38 * @param[in] cv condition variable 39 * @return zero on no errors, non-zero on errors 40 * @see metal_condition_wait, metal_condition_broadcast 41 */ 42 static inline int metal_condition_signal(struct metal_condition *cv); 43 44 /** 45 * @brief Notify all waiters. 46 * Before calling this function, the caller 47 * should have acquired the mutex. 48 * @param[in] cv condition variable 49 * @return zero on no errors, non-zero on errors 50 * @see metal_condition_wait, metal_condition_signal 51 */ 52 static inline int metal_condition_broadcast(struct metal_condition *cv); 53 54 /** 55 * @brief Block until the condition variable is notified. 56 * Before calling this function, the caller should 57 * have acquired the mutex. 58 * @param[in] cv condition variable 59 * @param[in] m mutex 60 * @return 0 on success, non-zero on failure. 61 * @see metal_condition_signal 62 */ 63 int metal_condition_wait(struct metal_condition *cv, metal_mutex_t *m); 64 65 #include <metal/system/generic/condition.h> 66 67 /** @} */ 68 69 #ifdef __cplusplus 70 } 71 #endif 72 73 #endif /* __METAL_CONDITION__H__ */ 74