1 /* 2 * Copyright (c) 2018, Pinecone Inc. and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /* 8 * @file nuttx/condition.c 9 * @brief NuttX libmetal condition variable handling. 10 */ 11 12 #include <metal/condition.h> 13 #include <metal/irq.h> 14 metal_condition_wait(struct metal_condition * cv,metal_mutex_t * m)15int metal_condition_wait(struct metal_condition *cv, 16 metal_mutex_t *m) 17 { 18 unsigned int flags; 19 20 /* Check if the mutex has been acquired */ 21 if (!cv || !m || !metal_mutex_is_acquired(m)) 22 return -EINVAL; 23 24 flags = metal_irq_save_disable(); 25 /* Release the mutex first. */ 26 metal_mutex_release(m); 27 nxsem_wait_uninterruptible(&cv->cond.sem); 28 metal_irq_restore_enable(flags); 29 /* Acquire the mutex again. */ 30 metal_mutex_acquire(m); 31 return 0; 32 } 33