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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [arch/] [i960/] [kernel/] [semaphore.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *   FILE: semaphore.c
3
 * AUTHOR: kma@cse.ogi.edu
4
 *  DESCR: interrupt-safe i960 semaphore implementation; isn't ready for SMP
5
 */
6
 
7
#ident "$Id: semaphore.c,v 1.1.1.1 2001-09-10 07:43:56 simons Exp $"
8
#include <asm/semaphore.h>
9
#include <linux/sched.h>
10
 
11
extern int __down_common(struct semaphore* sem, int intrflag)
12
{
13
        long flags;
14
        int retval=0;
15
 
16
        save_flags(flags);
17
        cli();
18
 
19
        if (--sem->count < 0) {
20
                if (intrflag) {
21
                        interruptible_sleep_on(&sem->wait);
22
                        if (current->signal & ~current->blocked) {
23
                                retval = -1;
24
                        }
25
                }
26
                else
27
                        sleep_on(&sem->wait);
28
        }
29
        restore_flags(flags);
30
        return retval;
31
}
32
 
33
void down(struct semaphore * sem)
34
{
35
        __down_common(sem, 0);
36
}
37
 
38
 
39
/*
40
 * This version waits in interruptible state so that the waiting
41
 * process can be killed.  The down_failed_interruptible routine
42
 * returns negative for signalled and zero for semaphore acquired.
43
 */
44
extern int down_interruptible(struct semaphore * sem)
45
{
46
        return __down_common(sem, 1);
47
}
48
 
49
 
50
/*
51
 * Primitives to spin on a lock.  Needed only for SMP.
52
 */
53
extern void get_buzz_lock(int *lock_ptr)
54
{
55
#ifdef __SMP__
56
        while (xchg(lock_ptr,1) != 0) ;
57
#endif
58
}
59
 
60
extern void give_buzz_lock(int *lock_ptr)
61
{
62
#ifdef __SMP__
63
        *lock_ptr = 0 ;
64
#endif
65
}
66
 
67
 
68
/*
69
 * We wake people up only if the semaphore was negative (== somebody was
70
 * waiting on it).
71
 */
72
extern void up(struct semaphore * sem)
73
{
74
        long flags;
75
        save_flags(flags);
76
        cli();
77
 
78
        if (sem->count++ < 0)
79
                wake_up(&sem->wait);
80
 
81
        restore_flags(flags);
82
}
83
 

powered by: WebSVN 2.1.0

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