blob: 2832f8ed4d6862a75efb269c9d5bbc08b283b244 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#ifndef _SPARC_SEMAPHORE_H
#define _SPARC_SEMAPHORE_H
/* Dinky, good for nothing, just barely irq safe, Sparc semaphores. */
#ifdef __KERNEL__
#include <asm/atomic.h>
struct semaphore {
atomic_t count;
int waking;
struct wait_queue * wait;
};
#define MUTEX ((struct semaphore) { ATOMIC_INIT(1), 0, NULL })
#define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), 0, NULL })
extern void __down(struct semaphore * sem);
extern int __down_interruptible(struct semaphore * sem);
extern void __up(struct semaphore * sem);
#define sema_init(sem, val) atomic_set(&((sem)->count), val)
#define wake_one_more(sem) \
do { \
unsigned long flags; \
save_and_cli(flags); \
sem->waking++; \
restore_flags(flags); \
} while(0)
#define waking_non_zero(sem) \
({ unsigned long flags; \
int ret = 0; \
save_and_cli(flags); \
if (sem->waking > 0) { \
sem->waking--; \
ret = 1; \
} \
restore_flags(flags); \
ret; \
})
/* This isn't quite as clever as the x86 side, I'll be fixing this
* soon enough.
*/
extern inline void down(struct semaphore * sem)
{
if (atomic_dec_return(&sem->count) < 0)
__down(sem);
}
extern inline int down_interruptible(struct semaphore * sem)
{
int ret = 0;
if(atomic_dec_return(&sem->count) < 0)
ret = __down_interruptible(sem);
return ret;
}
extern inline void up(struct semaphore * sem)
{
if (atomic_inc_return(&sem->count) <= 0)
__up(sem);
}
#endif /* __KERNEL__ */
#endif /* !(_SPARC_SEMAPHORE_H) */
|