libmetal
Loading...
Searching...
No Matches
mutex.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/mutex.h
9 * @brief NuttX mutex primitives for libmetal.
10 */
11
12#ifndef __METAL_MUTEX__H__
13#error "Include metal/mutex.h instead of metal/nuttx/mutex.h"
14#endif
15
16#ifndef __METAL_NUTTX_MUTEX__H__
17#define __METAL_NUTTX_MUTEX__H__
18
19#include <nuttx/mutex.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25typedef mutex_t metal_mutex_t;
26
27/*
28 * METAL_MUTEX_INIT - used for initializing an mutex elmenet in a static struct
29 * or global
30 */
31#define METAL_MUTEX_INIT(m) MUTEX_INITIALIZER
32/*
33 * METAL_MUTEX_DEFINE - used for defining and initializing a global or
34 * static singleton mutex
35 */
36#define METAL_MUTEX_DEFINE(m) metal_mutex_t m = MUTEX_INITIALIZER
37
38static inline void __metal_mutex_init(metal_mutex_t *mutex)
39{
40 nxmutex_init(mutex);
41}
42
43static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
44{
45 nxmutex_destroy(mutex);
46}
47
49{
50 return nxmutex_trylock(mutex);
51}
52
53static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
54{
55 nxmutex_lock(mutex);
56}
57
58static inline void __metal_mutex_release(metal_mutex_t *mutex)
59{
60 nxmutex_unlock(mutex);
61}
62
64{
65 return nxmutex_is_locked(mutex);
66}
67
68#ifdef __cplusplus
69}
70#endif
71
72#endif /* __METAL_NUTTX_MUTEX__H__ */
Definition: mutex.h:25
static void __metal_mutex_release(metal_mutex_t *mutex)
Definition: mutex.h:75
static void __metal_mutex_deinit(metal_mutex_t *mutex)
Definition: mutex.h:48
static int __metal_mutex_try_acquire(metal_mutex_t *mutex)
Definition: mutex.h:53
static int __metal_mutex_is_acquired(metal_mutex_t *mutex)
Definition: mutex.h:80
static void __metal_mutex_acquire(metal_mutex_t *mutex)
Definition: mutex.h:65
static void __metal_mutex_init(metal_mutex_t *mutex)
Definition: mutex.h:43