| Christoph Lameter | d3cb487 | 2006-01-06 00:11:20 -0800 | [diff] [blame] | 1 | #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 Morton | 5998bf1 | 2006-01-08 01:00:29 -0800 | [diff] [blame] | 11 | #include <asm/types.h> | 
| Christoph Lameter | d3cb487 | 2006-01-06 00:11:20 -0800 | [diff] [blame] | 12 |  | 
|  | 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 |  | 
|  | 23 | typedef atomic64_t atomic_long_t; | 
|  | 24 |  | 
|  | 25 | #define ATOMIC_LONG_INIT(i)	ATOMIC64_INIT(i) | 
|  | 26 |  | 
|  | 27 | static 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 |  | 
|  | 34 | static inline void atomic_long_set(atomic_long_t *l, long i) | 
|  | 35 | { | 
|  | 36 | atomic64_t *v = (atomic64_t *)l; | 
|  | 37 |  | 
| Kyle McMartin | 6b4977c | 2006-01-15 12:10:55 -0500 | [diff] [blame] | 38 | atomic64_set(v, i); | 
| Christoph Lameter | d3cb487 | 2006-01-06 00:11:20 -0800 | [diff] [blame] | 39 | } | 
|  | 40 |  | 
|  | 41 | static inline void atomic_long_inc(atomic_long_t *l) | 
|  | 42 | { | 
|  | 43 | atomic64_t *v = (atomic64_t *)l; | 
|  | 44 |  | 
|  | 45 | atomic64_inc(v); | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | static inline void atomic_long_dec(atomic_long_t *l) | 
|  | 49 | { | 
|  | 50 | atomic64_t *v = (atomic64_t *)l; | 
|  | 51 |  | 
|  | 52 | atomic64_dec(v); | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 | static 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 |  | 
|  | 62 | static 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 |  | 
|  | 71 | typedef atomic_t atomic_long_t; | 
|  | 72 |  | 
|  | 73 | #define ATOMIC_LONG_INIT(i)	ATOMIC_INIT(i) | 
|  | 74 | static 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 |  | 
|  | 81 | static 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 |  | 
|  | 88 | static inline void atomic_long_inc(atomic_long_t *l) | 
|  | 89 | { | 
|  | 90 | atomic_t *v = (atomic_t *)l; | 
|  | 91 |  | 
|  | 92 | atomic_inc(v); | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | static inline void atomic_long_dec(atomic_long_t *l) | 
|  | 96 | { | 
|  | 97 | atomic_t *v = (atomic_t *)l; | 
|  | 98 |  | 
|  | 99 | atomic_dec(v); | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | static 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 |  | 
|  | 109 | static 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 |