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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [or32/] [kernel/] [semaphore.c] - Blame information for rev 1777

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

Line No. Rev Author Line
1 1624 jcastillo
/*
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
#include <asm/semaphore.h>
8
#include <linux/sched.h>
9
 
10
extern int __down_common(struct semaphore* sem, int intrflag)
11
{
12
        long flags;
13
        int retval=0;
14
 
15
        save_flags(flags);
16
        cli();
17
 
18
        if (--sem->count < 0) {
19
                if (intrflag) {
20
                        interruptible_sleep_on(&sem->wait);
21
                        if (current->signal & ~current->blocked) {
22
                                retval = -1;
23
                        }
24
                }
25
                else
26
                        sleep_on(&sem->wait);
27
        }
28
        restore_flags(flags);
29
        return retval;
30
}
31
 
32
void down(struct semaphore * sem)
33
{
34
        __down_common(sem, 0);
35
}
36
 
37
 
38
/*
39
 * This version waits in interruptible state so that the waiting
40
 * process can be killed.  The down_failed_interruptible routine
41
 * returns negative for signalled and zero for semaphore acquired.
42
 */
43
extern int down_interruptible(struct semaphore * sem)
44
{
45
        return __down_common(sem, 1);
46
        return 0;
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.