coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
atomic.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
3
#ifndef ARCH_SMP_ATOMIC_H
4
#define ARCH_SMP_ATOMIC_H
5
6
/*
7
* Make sure gcc doesn't try to be clever and move things around
8
* on us. We need to use _exactly_ the address the user gave us,
9
* not some alias that contains the same information.
10
*/
11
typedef
struct
{
volatile
int
counter; }
atomic_t
;
12
13
#define ATOMIC_INIT(i) { (i) }
14
15
/** @file x86/include/arch/smp/atomic.h
16
*
17
* Atomic operations that C can't guarantee us. Useful for
18
* resource counting etc..
19
*/
20
21
/**
22
* atomic_read - read atomic variable
23
* @param v: pointer of type atomic_t
24
*
25
* Atomically reads the value of v. Note that the guaranteed
26
* useful range of an atomic_t is only 24 bits.
27
*/
28
#define atomic_read(v) ((v)->counter)
29
30
/**
31
* atomic_set - set atomic variable
32
* @param v: pointer of type atomic_t
33
* @param i: required value
34
*
35
* Atomically sets the value of v to i. Note that the guaranteed
36
* useful range of an atomic_t is only 24 bits.
37
*/
38
#define atomic_set(v, i) (((v)->counter) = (i))
39
40
/**
41
* atomic_inc - increment atomic variable
42
* @param v: pointer of type atomic_t
43
*
44
* Atomically increments v by 1. Note that the guaranteed
45
* useful range of an atomic_t is only 24 bits.
46
*/
47
static
__always_inline
void
atomic_inc
(
atomic_t
*v)
48
{
49
__asm__ __volatile__(
50
"lock ; incl %0"
51
:
"=m"
(v->
counter
)
52
:
"m"
(v->
counter
));
53
}
54
55
/**
56
* atomic_dec - decrement atomic variable
57
* @param v: pointer of type atomic_t
58
*
59
* Atomically decrements v by 1. Note that the guaranteed
60
* useful range of an atomic_t is only 24 bits.
61
*/
62
static
__always_inline
void
atomic_dec
(
atomic_t
*v)
63
{
64
__asm__ __volatile__(
65
"lock ; decl %0"
66
:
"=m"
(v->
counter
)
67
:
"m"
(v->
counter
));
68
}
69
70
#endif
/* ARCH_SMP_ATOMIC_H */
atomic_dec
static __always_inline void atomic_dec(atomic_t *v)
atomic_dec - decrement atomic variable
Definition:
atomic.h:62
atomic_inc
static __always_inline void atomic_inc(atomic_t *v)
atomic_inc - increment atomic variable
Definition:
atomic.h:47
__always_inline
#define __always_inline
Definition:
compiler.h:35
atomic_t
Definition:
atomic.h:8
atomic_t::counter
volatile int counter
Definition:
atomic.h:8
src
arch
x86
include
arch
smp
atomic.h
Generated by
1.9.1