Subversion Repositories HelenOS

Rev

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

Rev 475 Rev 477
Line 32... Line 32...
32
#include <arch/types.h>
32
#include <arch/types.h>
33
 
33
 
34
#define atomic_inc(x)   (a_add(x,1))
34
#define atomic_inc(x)   (a_add(x,1))
35
#define atomic_dec(x)   (a_sub(x,1))
35
#define atomic_dec(x)   (a_sub(x,1))
36
 
36
 
-
 
37
#define atomic_inc_pre(x) (a_add(x,1)-1)
-
 
38
#define atomic_dec_pre(x) (a_sub(x,1)+1)
-
 
39
 
-
 
40
#define atomic_inc_post(x) (a_add(x,1))
-
 
41
#define atomic_dec_post(x) (a_sub(x,1))
-
 
42
 
-
 
43
 
37
typedef volatile __u32 atomic_t;
44
typedef volatile __u32 atomic_t;
38
 
45
 
39
/*
46
/*
40
 * Atomic addition
47
 * Atomic addition
41
 *
48
 *
42
 * This case is harder, and we have to use the special LL and SC operations
49
 * This case is harder, and we have to use the special LL and SC operations
43
 * to achieve atomicity. The instructions are similar to LW (load) and SW
50
 * to achieve atomicity. The instructions are similar to LW (load) and SW
44
 * (store), except that the LL (load-linked) instruction loads the address
51
 * (store), except that the LL (load-linked) instruction loads the address
45
 * of the variable to a special register and if another process writes to
52
 * of the variable to a special register and if another process writes to
46
 * the same location, the SC (store-conditional) instruction fails.
53
 * the same location, the SC (store-conditional) instruction fails.
-
 
54
 
-
 
55
 Returns (*val)+i
-
 
56
 
47
 */
57
 */
48
static inline atomic_t a_add(atomic_t *val, int i)
58
static inline atomic_t a_add(atomic_t *val, int i)
49
{
59
{
50
    atomic_t tmp, tmp2;
60
    atomic_t tmp, tmp2;
51
 
61
 
Line 70... Line 80...
70
 
80
 
71
/*
81
/*
72
 * Atomic subtraction
82
 * Atomic subtraction
73
 *
83
 *
74
 * Implemented in the same manner as a_add, except we substract the value.
84
 * Implemented in the same manner as a_add, except we substract the value.
-
 
85
 
-
 
86
 Returns (*val)-i
-
 
87
 
75
 */
88
 */
76
static inline atomic_t a_sub(atomic_t *val, int i)
89
static inline atomic_t a_sub(atomic_t *val, int i)
77
 
90
 
78
{
91
{
79
    atomic_t tmp, tmp2;
92
    atomic_t tmp, tmp2;