Subversion Repositories HelenOS-historic

Rev

Rev 625 | Rev 1104 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 625 Rev 627
Line 31... Line 31...
31
 
31
 
32
#include <arch/types.h>
32
#include <arch/types.h>
33
 
33
 
34
typedef struct { volatile __u64 count; } atomic_t;
34
typedef struct { volatile __u64 count; } atomic_t;
35
 
35
 
-
 
36
/** Atomic addition.
-
 
37
 *
-
 
38
 * @param val Atomic value.
-
 
39
 * @param imm Value to add.
-
 
40
 *
-
 
41
 * @return Value after addition.
-
 
42
 */
36
static inline atomic_t atomic_add(atomic_t *val, int imm)
43
static inline count_t atomic_add(atomic_t *val, int imm)
37
{
44
{
38
    atomic_t v;
45
    count_t v;
39
 
46
 
40
   
-
 
41
    __asm__ volatile ("fetchadd8.rel %0 = %1, %2\n" : "=r" (v), "+m" (val->count) : "i" (imm));
47
    __asm__ volatile ("fetchadd8.rel %0 = %1, %2\n" : "=r" (v), "+m" (val->count) : "i" (imm));
42
 
48
 
43
    return v;
49
    return v;
44
}
50
}
45
 
51
 
Line 54... Line 60...
54
}
60
}
55
 
61
 
56
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
62
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
57
static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
63
static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
58
 
64
 
-
 
65
static inline count_t atomic_inc_pre(atomic_t *val) { return atomic_add(val, 1); }
-
 
66
static inline count_t atomic_dec_pre(atomic_t *val) { return atomic_add(val, -1); }
59
 
67
 
60
static inline atomic_t atomic_inc_pre(atomic_t *val) { return atomic_add(val, 1); }
-
 
61
static inline atomic_t atomic_dec_pre(atomic_t *val) { return atomic_add(val, -1); }
-
 
62
 
-
 
63
 
-
 
64
static inline atomic_t atomic_inc_post(atomic_t *val) { return atomic_add(val, 1) + 1; }
68
static inline count_t atomic_inc_post(atomic_t *val) { return atomic_add(val, 1) + 1; }
65
static inline atomic_t atomic_dec_post(atomic_t *val) { return atomic_add(val, -1) - 1; }
69
static inline count_t atomic_dec_post(atomic_t *val) { return atomic_add(val, -1) - 1; }
66
 
70
 
67
#endif
71
#endif