Xenomai
3.1
atomic.h
1
19
#ifndef _BOILERPLATE_ATOMIC_H
20
#define _BOILERPLATE_ATOMIC_H
21
22
#include <xeno_config.h>
23
24
typedef
struct
{
int
v; }
atomic_t
;
25
26
typedef
struct
{
long
v; } atomic_long_t;
27
28
#define ATOMIC_INIT(__n) { (__n) }
29
30
static
inline
long
atomic_long_read(
const
atomic_long_t *ptr)
31
{
32
return
ptr->v;
33
}
34
35
static
inline
void
atomic_long_set(atomic_long_t *ptr,
long
v)
36
{
37
ptr->v = v;
38
}
39
40
static
inline
int
atomic_read(
const
atomic_t
*ptr)
41
{
42
return
ptr->v;
43
}
44
45
static
inline
void
atomic_set(
atomic_t
*ptr,
long
v)
46
{
47
ptr->v = v;
48
}
49
50
#ifndef atomic_cmpxchg
51
#define atomic_cmpxchg(__ptr, __old, __new) \
52
__sync_val_compare_and_swap(&(__ptr)->v, __old, __new)
53
#endif
54
55
#ifndef atomic_sub_fetch
56
#define atomic_sub_fetch(__ptr, __n) \
57
__sync_sub_and_fetch(&(__ptr)->v, __n)
58
#endif
59
60
#ifndef atomic_add_fetch
61
#define atomic_add_fetch(__ptr, __n) \
62
__sync_add_and_fetch(&(__ptr)->v, __n)
63
#endif
64
65
#ifdef CONFIG_SMP
66
#ifndef smp_mb
67
#define smp_mb() __sync_synchronize()
68
#endif
69
#ifndef smp_rmb
70
#define smp_rmb() smp_mb()
71
#endif
72
#ifndef smp_wmb
73
#define smp_wmb() smp_mb()
74
#endif
75
#else
/* !CONFIG_SMP */
76
#define smp_mb() do { } while (0)
77
#define smp_rmb() do { } while (0)
78
#define smp_wmb() do { } while (0)
79
#endif
/* !CONFIG_SMP */
80
81
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
82
83
#define compiler_barrier() __asm__ __volatile__("": : :"memory")
84
85
#ifndef cpu_relax
86
#define cpu_relax() __sync_synchronize()
87
#endif
88
89
#endif
/* _BOILERPLATE_ATOMIC_H */
atomic_t
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition:
atomic.h:24
include
boilerplate
atomic.h
Generated by
1.8.14