libmetal
Loading...
Searching...
No Matches
condition.h
Go to the documentation of this file.
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.h
9 * @brief NuttX condition variable primitives for libmetal.
10 */
11
12#ifndef __METAL_CONDITION__H__
13#error "Include metal/condition.h instead of metal/nuttx/condition.h"
14#endif
15
16#ifndef __METAL_NUTTX_CONDITION__H__
17#define __METAL_NUTTX_CONDITION__H__
18
19#include <pthread.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25struct metal_condition {
26 pthread_cond_t cond;
27};
28
30#define METAL_CONDITION_INIT {PTHREAD_COND_INITIALIZER}
31
32static inline void metal_condition_init(struct metal_condition *cv)
33{
34 pthread_cond_init(&cv->cond, NULL);
35}
36
37static inline int metal_condition_signal(struct metal_condition *cv)
38{
39 return -pthread_cond_signal(&cv->cond);
40}
41
42static inline int metal_condition_broadcast(struct metal_condition *cv)
43{
44 return -pthread_cond_broadcast(&cv->cond);
45}
46
47#ifdef __cplusplus
48}
49#endif
50
51#endif /* __METAL_NUTTX_CONDITION__H__ */
static int metal_condition_signal(struct metal_condition *cv)
Notify one waiter. Before calling this function, the caller should have acquired the mutex.
static int metal_condition_broadcast(struct metal_condition *cv)
Notify all waiters. Before calling this function, the caller should have acquired the mutex.
static void metal_condition_init(struct metal_condition *cv)
Initialize a libmetal condition variable.
Definition condition.h:25
pthread_cond_t cond
Definition condition.h:26