OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-alpha/] [atomic.h] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1632 jcastillo
#ifndef __ARCH_ALPHA_ATOMIC__
2
#define __ARCH_ALPHA_ATOMIC__
3
 
4
/*
5
 * Atomic operations that C can't guarantee us.  Useful for
6
 * resource counting etc...
7
 *
8
 * But use these as seldom as possible since they are much more slower
9
 * than regular operations.
10
 */
11
 
12
/*
13
 * Make sure gcc doesn't try to be clever and move things around
14
 * on us. We need to use _exactly_ the address the user gave us,
15
 * not some alias that contains the same information.
16
 */
17
#define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x)
18
 
19
typedef int atomic_t;
20
 
21
extern __inline__ void atomic_add(atomic_t i, atomic_t * v)
22
{
23
        unsigned long temp;
24
        __asm__ __volatile__(
25
                "\n1:\t"
26
                "ldl_l %0,%1\n\t"
27
                "addl %0,%2,%0\n\t"
28
                "stl_c %0,%1\n\t"
29
                "beq %0,1b\n"
30
                "2:"
31
                :"=&r" (temp),
32
                 "=m" (__atomic_fool_gcc(v))
33
                :"Ir" (i),
34
                 "m" (__atomic_fool_gcc(v)));
35
}
36
 
37
extern __inline__ void atomic_sub(atomic_t i, atomic_t * v)
38
{
39
        unsigned long temp;
40
        __asm__ __volatile__(
41
                "\n1:\t"
42
                "ldl_l %0,%1\n\t"
43
                "subl %0,%2,%0\n\t"
44
                "stl_c %0,%1\n\t"
45
                "beq %0,1b\n"
46
                "2:"
47
                :"=&r" (temp),
48
                 "=m" (__atomic_fool_gcc(v))
49
                :"Ir" (i),
50
                 "m" (__atomic_fool_gcc(v)));
51
}
52
 
53
/*
54
 * Same as above, but return the result value
55
 */
56
extern __inline__ long atomic_add_return(atomic_t i, atomic_t * v)
57
{
58
        long temp, result;
59
        __asm__ __volatile__(
60
                "\n1:\t"
61
                "ldl_l %0,%1\n\t"
62
                "addl %0,%3,%0\n\t"
63
                "bis %0,%0,%2\n\t"
64
                "stl_c %0,%1\n\t"
65
                "beq %0,1b\n"
66
                "2:"
67
                :"=&r" (temp),
68
                 "=m" (__atomic_fool_gcc(v)),
69
                 "=&r" (result)
70
                :"Ir" (i),
71
                 "m" (__atomic_fool_gcc(v)));
72
        return result;
73
}
74
 
75
extern __inline__ long atomic_sub_return(atomic_t i, atomic_t * v)
76
{
77
        long temp, result;
78
        __asm__ __volatile__(
79
                "\n1:\t"
80
                "ldl_l %0,%1\n\t"
81
                "subl %0,%3,%0\n\t"
82
                "bis %0,%0,%2\n\t"
83
                "stl_c %0,%1\n\t"
84
                "beq %0,1b\n"
85
                "2:"
86
                :"=&r" (temp),
87
                 "=m" (__atomic_fool_gcc(v)),
88
                 "=&r" (result)
89
                :"Ir" (i),
90
                 "m" (__atomic_fool_gcc(v)));
91
        return result;
92
}
93
 
94
#define atomic_dec_return(v) atomic_sub_return(1,(v))
95
#define atomic_inc_return(v) atomic_add_return(1,(v))
96
 
97
#define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
98
#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
99
 
100
#define atomic_inc(v) atomic_add(1,(v))
101
#define atomic_dec(v) atomic_sub(1,(v))
102
 
103
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.