|
|
1.1 root 1: #ifndef __ARCH_I386_ATOMIC__
2: #define __ARCH_I386_ATOMIC__
3:
4: /*
5: * Atomic operations that C can't guarantee us. Useful for
6: * resource counting etc..
7: */
8:
9: #ifdef __SMP__
10: #define LOCK "lock ; "
11: #else
12: #define LOCK ""
13: #endif
14:
15: /*
16: * Make sure gcc doesn't try to be clever and move things around
17: * on us. We need to use _exactly_ the address the user gave us,
18: * not some alias that contains the same information.
19: */
20: #define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x)
21:
22: typedef int atomic_t;
23:
1.1.1.2 ! root 24: #define atomic_read(v) (*v)
! 25:
1.1 root 26: static __inline__ void atomic_add(atomic_t i, atomic_t *v)
27: {
28: __asm__ __volatile__(
29: LOCK "addl %1,%0"
30: :"=m" (__atomic_fool_gcc(v))
31: :"ir" (i), "m" (__atomic_fool_gcc(v)));
32: }
33:
34: static __inline__ void atomic_sub(atomic_t i, atomic_t *v)
35: {
36: __asm__ __volatile__(
37: LOCK "subl %1,%0"
38: :"=m" (__atomic_fool_gcc(v))
39: :"ir" (i), "m" (__atomic_fool_gcc(v)));
40: }
41:
42: static __inline__ void atomic_inc(atomic_t *v)
43: {
44: __asm__ __volatile__(
45: LOCK "incl %0"
46: :"=m" (__atomic_fool_gcc(v))
47: :"m" (__atomic_fool_gcc(v)));
48: }
49:
50: static __inline__ void atomic_dec(atomic_t *v)
51: {
52: __asm__ __volatile__(
53: LOCK "decl %0"
54: :"=m" (__atomic_fool_gcc(v))
55: :"m" (__atomic_fool_gcc(v)));
56: }
57:
58: static __inline__ int atomic_dec_and_test(atomic_t *v)
59: {
60: unsigned char c;
61:
62: __asm__ __volatile__(
63: LOCK "decl %0; sete %1"
64: :"=m" (__atomic_fool_gcc(v)), "=qm" (c)
65: :"m" (__atomic_fool_gcc(v)));
66: return c != 0;
67: }
68:
69: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.