libmetal
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
system
zephyr
condition.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
3
*
4
* SPDX-License-Identifier: BSD-3-Clause
5
*/
6
11
12
#ifndef __METAL_CONDITION__H__
13
#error "Include metal/condition.h instead of metal/generic/condition.h"
14
#endif
15
16
#ifndef __METAL_ZEPHYR_CONDITION__H__
17
#define __METAL_ZEPHYR_CONDITION__H__
18
19
#include <metal/atomic.h>
20
#include <metal/errno.h>
21
#include <stddef.h>
22
#include <stdint.h>
23
24
#ifdef __cplusplus
25
extern
"C"
{
26
#endif
27
28
struct
metal_condition
{
29
atomic_uintptr_t
mptr
;
35
36
atomic_int
v
;
37
};
38
40
#define METAL_CONDITION_INIT { ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0) }
41
42
static
inline
void
metal_condition_init
(
struct
metal_condition
*cv)
43
{
44
atomic_init
(&cv->
mptr
, 0);
45
atomic_init
(&cv->
v
, 0);
46
}
47
48
static
inline
int
metal_condition_signal
(
struct
metal_condition
*cv)
49
{
50
if
(!cv)
51
return
-
EINVAL
;
52
54
atomic_fetch_add
(&cv->
v
, 1);
55
return
0;
56
}
57
58
static
inline
int
metal_condition_broadcast
(
struct
metal_condition
*cv)
59
{
60
return
metal_condition_signal
(cv);
61
}
62
63
64
#ifdef __cplusplus
65
}
66
#endif
67
68
#endif
/* __METAL_ZEPHYR_CONDITION__H__ */
atomic_fetch_add
#define atomic_fetch_add(OBJ, VAL)
Definition
atomic.h:95
atomic_int
int atomic_int
Definition
atomic.h:24
atomic_init
#define atomic_init(OBJ, VAL)
Definition
atomic.h:52
atomic_uintptr_t
atomic_uint atomic_uintptr_t
Definition
atomic.h:26
EINVAL
#define EINVAL
Definition
errno.h:48
metal_condition_signal
static int metal_condition_signal(struct metal_condition *cv)
Notify one waiter. Before calling this function, the caller should have acquired the mutex.
metal_condition_broadcast
static int metal_condition_broadcast(struct metal_condition *cv)
Notify all waiters. Before calling this function, the caller should have acquired the mutex.
metal_condition_init
static void metal_condition_init(struct metal_condition *cv)
Initialize a libmetal condition variable.
metal_condition
Definition
condition.h:25
metal_condition::v
atomic_int v
Definition
condition.h:32
metal_condition::mptr
atomic_uintptr_t mptr
Definition
condition.h:29
Generated on
for libmetal by
1.17.0