blob: 42a95d9a0641b4059a96b464d7d0a0e38cbd1b33 [file] [log] [blame]
Christoph Lameterd3cb4872006-01-06 00:11:20 -08001#ifndef _ASM_GENERIC_ATOMIC_H
2#define _ASM_GENERIC_ATOMIC_H
3/*
4 * Copyright (C) 2005 Silicon Graphics, Inc.
5 * Christoph Lameter <clameter@sgi.com>
6 *
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)
26
27static inline long atomic_long_read(atomic_long_t *l)
28{
29 atomic64_t *v = (atomic64_t *)l;
30
31 return (long)atomic64_read(v);
32}
33
34static inline void atomic_long_set(atomic_long_t *l, long i)
35{
36 atomic64_t *v = (atomic64_t *)l;
37
Kyle McMartin6b4977c2006-01-15 12:10:55 -050038 atomic64_set(v, i);
Christoph Lameterd3cb4872006-01-06 00:11:20 -080039}
40
41static inline void atomic_long_inc(atomic_long_t *l)
42{
43 atomic64_t *v = (atomic64_t *)l;
44
45 atomic64_inc(v);
46}
47
48static inline void atomic_long_dec(atomic_long_t *l)
49{
50 atomic64_t *v = (atomic64_t *)l;
51
52 atomic64_dec(v);
53}
54
55static inline void atomic_long_add(long i, atomic_long_t *l)
56{
57 atomic64_t *v = (atomic64_t *)l;
58
59 atomic64_add(i, v);
60}
61
62static inline void atomic_long_sub(long i, atomic_long_t *l)
63{
64 atomic64_t *v = (atomic64_t *)l;
65
66 atomic64_sub(i, v);
67}
68
69#else
70
71typedef atomic_t atomic_long_t;
72
73#define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
74static inline long atomic_long_read(atomic_long_t *l)
75{
76 atomic_t *v = (atomic_t *)l;
77
78 return (long)atomic_read(v);
79}
80
81static inline void atomic_long_set(atomic_long_t *l, long i)
82{
83 atomic_t *v = (atomic_t *)l;
84
85 atomic_set(v, i);
86}
87
88static inline void atomic_long_inc(atomic_long_t *l)
89{
90 atomic_t *v = (atomic_t *)l;
91
92 atomic_inc(v);
93}
94
95static inline void atomic_long_dec(atomic_long_t *l)
96{
97 atomic_t *v = (atomic_t *)l;
98
99 atomic_dec(v);
100}
101
102static inline void atomic_long_add(long i, atomic_long_t *l)
103{
104 atomic_t *v = (atomic_t *)l;
105
106 atomic_add(i, v);
107}
108
109static inline void atomic_long_sub(long i, atomic_long_t *l)
110{
111 atomic_t *v = (atomic_t *)l;
112
113 atomic_sub(i, v);
114}
115
116#endif
117#endif