OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-alpha/] [semaphore.h] - Blame information for rev 1632

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1632 jcastillo
#ifndef _ALPHA_SEMAPHORE_H
2
#define _ALPHA_SEMAPHORE_H
3
 
4
/*
5
 * SMP- and interrupt-safe semaphores..
6
 *
7
 * (C) Copyright 1996 Linus Torvalds
8
 */
9
 
10
#include <asm/atomic.h>
11
#include <asm/system.h>
12
 
13
struct semaphore {
14
        atomic_t count;
15
        atomic_t waking;
16
        int lock;                       /* to make waking testing atomic */
17
        struct wait_queue * wait;
18
};
19
 
20
#define MUTEX ((struct semaphore) { 1, 0, 0, NULL })
21
#define MUTEX_LOCKED ((struct semaphore) { 0, 0, 0, NULL })
22
 
23
extern void __down(struct semaphore * sem);
24
extern int  __down_interruptible(struct semaphore * sem);
25
extern void __up(struct semaphore * sem);
26
 
27
/*
28
 * This isn't quite as clever as the x86 side, but the gp register
29
 * makes things a bit more complicated on the alpha..
30
 */
31
extern inline void down(struct semaphore * sem)
32
{
33
        if (atomic_dec_return(&sem->count) < 0)
34
                __down(sem);
35
}
36
 
37
/*
38
 * Primitives to spin on a lock.  Needed only for SMP version.
39
 */
40
extern inline void get_buzz_lock(int *lock_ptr)
41
{
42
#ifdef __SMP__
43
        while (xchg(lock_ptr,1) != 0) ;
44
#endif
45
} /* get_buzz_lock */
46
 
47
extern inline void give_buzz_lock(int *lock_ptr)
48
{
49
#ifdef __SMP__
50
        *lock_ptr = 0 ;
51
#endif
52
} /* give_buzz_lock */
53
 
54
extern inline int down_interruptible(struct semaphore * sem)
55
{
56
        int ret = 0;
57
        if (atomic_dec_return(&sem->count) < 0)
58
                ret = __down_interruptible(sem);
59
        return ret;
60
}
61
 
62
extern inline void up(struct semaphore * sem)
63
{
64
        if (atomic_inc_return(&sem->count) <= 0)
65
                __up(sem);
66
}
67
 
68
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.