libmetal
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
spinlock.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved.
3
*
4
* SPDX-License-Identifier: BSD-3-Clause
5
*/
6
11
12
#ifndef __METAL_SPINLOCK__H__
13
#define __METAL_SPINLOCK__H__
14
15
#include <metal/atomic.h>
16
#include <metal/cpu.h>
17
18
#ifdef __cplusplus
19
extern
"C"
{
20
#endif
21
25
26
struct
metal_spinlock
{
27
atomic_flag
v
;
28
};
29
31
#define METAL_SPINLOCK_INIT {ATOMIC_FLAG_INIT}
32
37
static
inline
void
metal_spinlock_init
(
struct
metal_spinlock
*slock)
38
{
39
atomic_flag_clear
(&slock->
v
);
40
}
41
47
static
inline
void
metal_spinlock_acquire
(
struct
metal_spinlock
*slock)
48
{
49
while
(
atomic_flag_test_and_set
(&slock->
v
)) {
50
metal_cpu_yield
();
51
}
52
}
53
59
static
inline
void
metal_spinlock_release
(
struct
metal_spinlock
*slock)
60
{
61
atomic_flag_clear
(&slock->
v
);
62
}
63
65
66
#ifdef __cplusplus
67
}
68
#endif
69
70
#endif
/* __METAL_SPINLOCK__H__ */
atomic_flag_test_and_set
#define atomic_flag_test_and_set(FLAG)
Definition
atomic.h:44
atomic_flag_clear
#define atomic_flag_clear(FLAG)
Definition
atomic.h:48
atomic_flag
int atomic_flag
Definition
atomic.h:19
metal_spinlock_init
static void metal_spinlock_init(struct metal_spinlock *slock)
Initialize a libmetal spinlock.
Definition
spinlock.h:37
metal_spinlock_release
static void metal_spinlock_release(struct metal_spinlock *slock)
Release a previously acquired spinlock.
Definition
spinlock.h:59
metal_spinlock_acquire
static void metal_spinlock_acquire(struct metal_spinlock *slock)
Acquire a spinlock.
Definition
spinlock.h:47
metal_cpu_yield
#define metal_cpu_yield()
Definition
cpu.h:15
metal_spinlock
Definition
spinlock.h:26
metal_spinlock::v
atomic_flag v
Definition
spinlock.h:27
Generated on
for libmetal by
1.17.0