source: trunk/packages/xen-3.1/xen-3.1/tools/vnet/vnetd/spinlock.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 1.1 KB
Line 
1#include "spinlock.h"
2
3int atomic_read(const atomic_t *v){
4    return v->val;
5}
6
7int atomic_dec_and_test(atomic_t *v){
8    if(v->val > 0){
9        v->val--;
10        return v->val == 0;
11    }
12    return 0;
13}
14
15void atomic_inc(atomic_t *v){
16    v->val++;
17}
18
19void atomic_set(atomic_t *v, int x){
20    v->val = x;
21}
22
23void spin_lock_init(spinlock_t *lock){
24    *lock = (spinlock_t){};
25}
26
27unsigned long _spin_lock_irqsave(spinlock_t *lock){
28    lock->val++;
29    return 0;
30}
31
32void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags){
33    lock->val--;
34}
35
36unsigned long _read_lock_irqsave(rwlock_t *lock){
37    lock->val++;
38    return 0;
39}
40
41void read_unlock_irqrestore(rwlock_t *lock, unsigned long flags){
42    lock->val--;
43}
44
45unsigned long _write_lock_irqsave(rwlock_t *lock){
46    lock->val++;
47    return 0;
48}
49
50void write_unlock_irqrestore(rwlock_t *lock, unsigned long flags){
51    lock->val--;
52}
53
54void init_MUTEX(struct semaphore *sem){
55    *sem = (struct semaphore){ .count = 1 };
56}
57
58void down(struct semaphore *sem){
59    sem->count--;
60}
61
62void up(struct semaphore *sem){
63    sem->count++;
64}
65
Note: See TracBrowser for help on using the repository browser.