Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
atomic.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Tilera Corporation. All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation, version 2.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11  * NON INFRINGEMENT. See the GNU General Public License for
12  * more details.
13  *
14  * Atomic primitives.
15  */
16 
17 #ifndef _ASM_TILE_ATOMIC_H
18 #define _ASM_TILE_ATOMIC_H
19 
20 #include <asm/cmpxchg.h>
21 
22 #ifndef __ASSEMBLY__
23 
24 #include <linux/compiler.h>
25 #include <linux/types.h>
26 
27 #define ATOMIC_INIT(i) { (i) }
28 
35 static inline int atomic_read(const atomic_t *v)
36 {
37  return ACCESS_ONCE(v->counter);
38 }
39 
47 #define atomic_sub_return(i, v) atomic_add_return((int)(-(i)), (v))
48 
56 #define atomic_sub(i, v) atomic_add((int)(-(i)), (v))
57 
66 #define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
67 
74 #define atomic_inc_return(v) atomic_add_return(1, (v))
75 
82 #define atomic_dec_return(v) atomic_sub_return(1, (v))
83 
90 #define atomic_inc(v) atomic_add(1, (v))
91 
98 #define atomic_dec(v) atomic_sub(1, (v))
99 
106 #define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
107 
114 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
115 
124 #define atomic_add_negative(i, v) (atomic_add_return((i), (v)) < 0)
125 
126 #endif /* __ASSEMBLY__ */
127 
128 #ifndef __tilegx__
129 #include <asm/atomic_32.h>
130 #else
131 #include <asm/atomic_64.h>
132 #endif
133 
134 #endif /* _ASM_TILE_ATOMIC_H */