blob: beaea541adfb705c768966161dc311e7cb74b461 [file] [log] [blame]
Arnd Bergmann72099ed2009-05-13 22:56:29 +00001#ifndef _ASM_GENERIC_ATOMIC_LONG_H
2#define _ASM_GENERIC_ATOMIC_LONG_H
Christoph Lameterd3cb4872006-01-06 00:11:20 -08003/*
4 * Copyright (C) 2005 Silicon Graphics, Inc.
Christoph Lametercde53532008-07-04 09:59:22 -07005 * Christoph Lameter
Christoph Lameterd3cb4872006-01-06 00:11:20 -08006 *
7 * Allows to provide arch independent atomic definitions without the need to
8 * edit all arch specific atomic.h files.
9 */
10
Andrew Morton5998bf12006-01-08 01:00:29 -080011#include <asm/types.h>
Christoph Lameterd3cb4872006-01-06 00:11:20 -080012
13/*
14 * Suppport for atomic_long_t
15 *
16 * Casts for parameters are avoided for existing atomic functions in order to
17 * avoid issues with cast-as-lval under gcc 4.x and other limitations that the
18 * macros of a platform may have.
19 */
20
21#if BITS_PER_LONG == 64
22
23typedef atomic64_t atomic_long_t;
24
25#define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
Will Deacon586b6102015-08-06 17:54:38 +010026#define ATOMIC_LONG_PFX(x) atomic64 ## x
Christoph Lameterd3cb4872006-01-06 00:11:20 -080027
Will Deacon586b6102015-08-06 17:54:38 +010028#else
Christoph Lameterd3cb4872006-01-06 00:11:20 -080029
30typedef atomic_t atomic_long_t;
31
32#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
Will Deacon586b6102015-08-06 17:54:38 +010033#define ATOMIC_LONG_PFX(x) atomic ## x
34
35#endif
36
Christoph Lameterd3cb4872006-01-06 00:11:20 -080037static inline long atomic_long_read(atomic_long_t *l)
38{
Will Deacon586b6102015-08-06 17:54:38 +010039 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Christoph Lameterd3cb4872006-01-06 00:11:20 -080040
Will Deacon586b6102015-08-06 17:54:38 +010041 return (long)ATOMIC_LONG_PFX(_read)(v);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080042}
43
44static inline void atomic_long_set(atomic_long_t *l, long i)
45{
Will Deacon586b6102015-08-06 17:54:38 +010046 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Christoph Lameterd3cb4872006-01-06 00:11:20 -080047
Will Deacon586b6102015-08-06 17:54:38 +010048 ATOMIC_LONG_PFX(_set)(v, i);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080049}
50
51static inline void atomic_long_inc(atomic_long_t *l)
52{
Will Deacon586b6102015-08-06 17:54:38 +010053 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Christoph Lameterd3cb4872006-01-06 00:11:20 -080054
Will Deacon586b6102015-08-06 17:54:38 +010055 ATOMIC_LONG_PFX(_inc)(v);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080056}
57
58static inline void atomic_long_dec(atomic_long_t *l)
59{
Will Deacon586b6102015-08-06 17:54:38 +010060 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Christoph Lameterd3cb4872006-01-06 00:11:20 -080061
Will Deacon586b6102015-08-06 17:54:38 +010062 ATOMIC_LONG_PFX(_dec)(v);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080063}
64
65static inline void atomic_long_add(long i, atomic_long_t *l)
66{
Will Deacon586b6102015-08-06 17:54:38 +010067 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Christoph Lameterd3cb4872006-01-06 00:11:20 -080068
Will Deacon586b6102015-08-06 17:54:38 +010069 ATOMIC_LONG_PFX(_add)(i, v);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080070}
71
72static inline void atomic_long_sub(long i, atomic_long_t *l)
73{
Will Deacon586b6102015-08-06 17:54:38 +010074 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Christoph Lameterd3cb4872006-01-06 00:11:20 -080075
Will Deacon586b6102015-08-06 17:54:38 +010076 ATOMIC_LONG_PFX(_sub)(i, v);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080077}
78
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070079static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
80{
Will Deacon586b6102015-08-06 17:54:38 +010081 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070082
Will Deacon586b6102015-08-06 17:54:38 +010083 return ATOMIC_LONG_PFX(_sub_and_test)(i, v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070084}
85
86static inline int atomic_long_dec_and_test(atomic_long_t *l)
87{
Will Deacon586b6102015-08-06 17:54:38 +010088 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070089
Will Deacon586b6102015-08-06 17:54:38 +010090 return ATOMIC_LONG_PFX(_dec_and_test)(v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070091}
92
93static inline int atomic_long_inc_and_test(atomic_long_t *l)
94{
Will Deacon586b6102015-08-06 17:54:38 +010095 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070096
Will Deacon586b6102015-08-06 17:54:38 +010097 return ATOMIC_LONG_PFX(_inc_and_test)(v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -070098}
99
100static inline int atomic_long_add_negative(long i, atomic_long_t *l)
101{
Will Deacon586b6102015-08-06 17:54:38 +0100102 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700103
Will Deacon586b6102015-08-06 17:54:38 +0100104 return ATOMIC_LONG_PFX(_add_negative)(i, v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700105}
106
107static inline long atomic_long_add_return(long i, atomic_long_t *l)
108{
Will Deacon586b6102015-08-06 17:54:38 +0100109 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700110
Will Deacon586b6102015-08-06 17:54:38 +0100111 return (long)ATOMIC_LONG_PFX(_add_return)(i, v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700112}
113
114static inline long atomic_long_sub_return(long i, atomic_long_t *l)
115{
Will Deacon586b6102015-08-06 17:54:38 +0100116 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700117
Will Deacon586b6102015-08-06 17:54:38 +0100118 return (long)ATOMIC_LONG_PFX(_sub_return)(i, v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700119}
120
121static inline long atomic_long_inc_return(atomic_long_t *l)
122{
Will Deacon586b6102015-08-06 17:54:38 +0100123 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700124
Will Deacon586b6102015-08-06 17:54:38 +0100125 return (long)ATOMIC_LONG_PFX(_inc_return)(v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700126}
127
128static inline long atomic_long_dec_return(atomic_long_t *l)
129{
Will Deacon586b6102015-08-06 17:54:38 +0100130 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700131
Will Deacon586b6102015-08-06 17:54:38 +0100132 return (long)ATOMIC_LONG_PFX(_dec_return)(v);
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700133}
134
Mathieu Desnoyers2856f5e2007-05-08 00:34:38 -0700135static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
136{
Will Deacon586b6102015-08-06 17:54:38 +0100137 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;
Mathieu Desnoyers2856f5e2007-05-08 00:34:38 -0700138
Will Deacon586b6102015-08-06 17:54:38 +0100139 return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u);
Mathieu Desnoyers2856f5e2007-05-08 00:34:38 -0700140}
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700141
Will Deacon586b6102015-08-06 17:54:38 +0100142#define atomic_long_inc_not_zero(l) \
143 ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l))
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700144#define atomic_long_cmpxchg(l, old, new) \
Will Deacon586b6102015-08-06 17:54:38 +0100145 (ATOMIC_LONG_PFX(_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), (old), (new)))
Mathieu Desnoyersbb2382c2007-05-08 00:34:19 -0700146#define atomic_long_xchg(v, new) \
Will Deacon586b6102015-08-06 17:54:38 +0100147 (ATOMIC_LONG_PFX(_xchg)((ATOMIC_LONG_PFX(_t) *)(v), (new)))
Adrian Bunk4b358e22006-12-06 20:40:28 -0800148
Arnd Bergmann72099ed2009-05-13 22:56:29 +0000149#endif /* _ASM_GENERIC_ATOMIC_LONG_H */