Subversion Repositories HelenOS-historic

Rev

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

Rev 111 Rev 153
Line 27... Line 27...
27
 */
27
 */
28
 
28
 
29
#include <arch.h>
29
#include <arch.h>
30
 
30
 
31
#include <arch/atomic.h>
31
#include <arch/atomic.h>
-
 
32
#include <arch/barrier.h>
32
#include <synch/spinlock.h>
33
#include <synch/spinlock.h>
33
 
34
 
34
#ifdef __SMP__
35
#ifdef __SMP__
35
 
36
 
36
void spinlock_initialize(spinlock_t *sl)
37
void spinlock_initialize(spinlock_t *sl)
Line 48... Line 49...
48
        if (i++ > 300000) {
49
        if (i++ > 300000) {
49
            printf("cpu%d: looping on spinlock %X, caller=%X\n", CPU->id, sl, caller);
50
            printf("cpu%d: looping on spinlock %X, caller=%X\n", CPU->id, sl, caller);
50
            i = 0;
51
            i = 0;
51
        }
52
        }
52
    }
53
    }
-
 
54
    CS_ENTER_BARRIER();
53
 
55
 
54
}
56
}
55
#else
57
#else
56
void spinlock_lock(spinlock_t *sl)
58
void spinlock_lock(spinlock_t *sl)
57
{
59
{
58
    /*
60
    /*
59
     * Each architecture has its own efficient/recommended
61
     * Each architecture has its own efficient/recommended
60
     * implementation of spinlock.
62
     * implementation of spinlock.
61
     */
63
     */
62
    spinlock_arch(&sl->val);
64
    spinlock_arch(&sl->val);
-
 
65
    CS_ENTER_BARRIER();
63
}
66
}
64
#endif
67
#endif
65
 
68
 
66
int spinlock_trylock(spinlock_t *sl)
69
int spinlock_trylock(spinlock_t *sl)
67
{
70
{
-
 
71
    int rc;
-
 
72
   
68
    return !test_and_set(&sl->val);
73
    rc = !test_and_set(&sl->val);
-
 
74
    CS_ENTER_BARRIER();
-
 
75
   
-
 
76
    return rc;
69
}
77
}
70
 
78
 
71
void spinlock_unlock(spinlock_t *sl)
79
void spinlock_unlock(spinlock_t *sl)
72
{
80
{
-
 
81
    CS_LEAVE_BARRIER();
73
    sl->val = 0;
82
    sl->val = 0;
74
}
83
}
75
 
84
 
76
#endif
85
#endif