[32] | 1 | #ifndef __ARCH_I386_ATOMIC__
|
---|
| 2 | #define __ARCH_I386_ATOMIC__
|
---|
| 3 |
|
---|
| 4 | #define LOCK
|
---|
| 5 |
|
---|
| 6 | typedef struct { int counter; } atomic_t;
|
---|
| 7 |
|
---|
| 8 | #define ATOMIC_INIT(i) { (i) }
|
---|
| 9 |
|
---|
| 10 | #define atomic_read(v) ((v)->counter)
|
---|
| 11 | #define atomic_set(v,i) (((v)->counter) = (i))
|
---|
| 12 |
|
---|
| 13 | void atomic_add(int i, volatile atomic_t *v);
|
---|
| 14 | void atomic_sub(int i, volatile atomic_t *v);
|
---|
| 15 |
|
---|
| 16 | void atomic_inc(volatile atomic_t *v);
|
---|
| 17 | #pragma aux atomic_inc = \
|
---|
| 18 | "lock inc dword ptr [eax]" \
|
---|
| 19 | parm [eax];
|
---|
| 20 |
|
---|
| 21 | void atomic_dec(volatile atomic_t *v);
|
---|
| 22 | #pragma aux atomic_dec = \
|
---|
| 23 | "lock dec dword ptr [eax]" \
|
---|
| 24 | parm [eax];
|
---|
| 25 |
|
---|
[118] | 26 | /**
|
---|
| 27 | * atomic_dec_and_test - decrement and test
|
---|
| 28 | * @v: pointer of type atomic_t
|
---|
| 29 | *
|
---|
| 30 | * Atomically decrements @v by 1 and
|
---|
| 31 | * returns true if the result is 0, or false for all other
|
---|
| 32 | * cases. Note that the guaranteed
|
---|
| 33 | * useful range of an atomic_t is only 24 bits.
|
---|
| 34 | */
|
---|
| 35 | static inline int atomic_dec_and_test(volatile atomic_t *v)
|
---|
| 36 | {
|
---|
| 37 | atomic_dec(v);
|
---|
| 38 | if (v->counter == 0)
|
---|
| 39 | return 1;
|
---|
| 40 | return 0;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[32] | 43 | extern int atomic_add_negative(int i, volatile atomic_t *v);
|
---|
| 44 |
|
---|
| 45 | /* These are x86-specific, used by some header files */
|
---|
| 46 | #define atomic_clear_mask(mask, addr)
|
---|
| 47 |
|
---|
[679] | 48 | /**
|
---|
| 49 | * atomic_add_return - add integer to atomic variable
|
---|
| 50 | * @i: integer value to add
|
---|
| 51 | * @v: pointer of type atomic_t
|
---|
| 52 | *
|
---|
| 53 | * Atomically adds @i to @v and returns the result
|
---|
| 54 | */
|
---|
| 55 | static inline int atomic_add_return(int i, atomic_t *v)
|
---|
| 56 | {
|
---|
| 57 | //unsigned long flags;
|
---|
| 58 | int temp;
|
---|
| 59 |
|
---|
| 60 | //raw_local_irq_save(flags); /* Don't trace it in an irqsoff handler */
|
---|
| 61 | temp = v->counter;
|
---|
| 62 | temp += i;
|
---|
| 63 | v->counter = temp;
|
---|
| 64 | //raw_local_irq_restore(flags);
|
---|
| 65 |
|
---|
| 66 | return temp;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /**
|
---|
| 70 | * atomic_sub_return - subtract integer from atomic variable
|
---|
| 71 | * @i: integer value to subtract
|
---|
| 72 | * @v: pointer of type atomic_t
|
---|
| 73 | *
|
---|
| 74 | * Atomically subtracts @i from @v and returns the result
|
---|
| 75 | */
|
---|
| 76 | static inline int atomic_sub_return(int i, atomic_t *v)
|
---|
| 77 | {
|
---|
| 78 | //unsigned long flags;
|
---|
| 79 | int temp;
|
---|
| 80 |
|
---|
| 81 | //raw_local_irq_save(flags); /* Don't trace it in an irqsoff handler */
|
---|
| 82 | temp = v->counter;
|
---|
| 83 | temp -= i;
|
---|
| 84 | v->counter = temp;
|
---|
| 85 | //raw_local_irq_restore(flags);
|
---|
| 86 |
|
---|
| 87 | return temp;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[32] | 90 | #define atomic_set_mask(mask, addr)
|
---|
[679] | 91 | #define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
|
---|
| 92 | #define atomic_inc_return(v) atomic_add_return(1, (v))
|
---|
[32] | 93 |
|
---|
[679] | 94 | typedef struct {
|
---|
| 95 | long long counter;
|
---|
| 96 | } atomic64_t;
|
---|
| 97 |
|
---|
| 98 | typedef atomic64_t atomic_long_t;
|
---|
[32] | 99 | #endif
|
---|