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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [include/] [asm/] [semaphore.h] - Blame information for rev 1778

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

Line No. Rev Author Line
1 199 simons
#ifndef _OR1K_SEMAPHORE_H
2
#define _OR1K_SEMAPHORE_H
3
 
4
#include <linux/linkage.h>
5
 
6
/*
7
 * SMP- and interrupt-safe semaphores..
8
 *
9
 * (C) Copyright 1996 Linus Torvalds
10
 *
11
 */
12
 
13
struct semaphore {
14
        int count;
15
        int 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
asmlinkage void __down_failed(void /* special register calling convention */);
24
asmlinkage int  __down_failed_interruptible(void);  /* params in registers */
25
asmlinkage void __up_wakeup(void /* special register calling convention */);
26
 
27
extern void __down(struct semaphore * sem);
28
extern void __up(struct semaphore * sem);
29
 
30
/*
31
 * This is ugly, but we want the default case to fall through.
32
 * "down_failed" is a special asm handler that calls the C
33
 * routine that actually waits. See arch/m68k/lib/semaphore.S
34
 */
35
extern inline void down(struct semaphore * sem)
36
{
37
/* SIMON */
38
#if 0
39
        register struct semaphore *sem1 __asm__ ("%a1") = sem;
40
        __asm__ __volatile__(
41
                "| atomic down operation\n\t"
42
                "lea %%pc@(1f),%%a0\n\t"
43
                "subql #1,%0@\n\t"
44
                "jmi " SYMBOL_NAME_STR(__down_failed) "\n"
45
                "1:"
46
                : /* no outputs */
47
                : "a" (sem1)
48
                : "%a0", "memory");
49
#endif
50
}
51
 
52
 
53
/*
54
 * This version waits in interruptible state so that the waiting
55
 * process can be killed.  The down_failed_interruptible routine
56
 * returns negative for signalled and zero for semaphore acquired.
57
 */
58
extern inline int down_interruptible(struct semaphore * sem)
59
{
60
/* SIMON */
61
#if 0
62
        register int ret __asm__ ("%d0");
63
        register struct semaphore *sem1 __asm__ ("%a1") = sem;
64
        __asm__ __volatile__(
65
                "| atomic down operation\n\t"
66
                "lea %%pc@(1f),%%a0\n\t"
67
                "subql #1,%1@\n\t"
68
                "jmi " SYMBOL_NAME_STR(__down_failed_interruptible) "\n"
69
                "clrl %0\n"
70
                "1:"
71
                : "=d" (ret)
72
                : "a" (sem1)
73
                : "%a0", "memory");
74
        return(ret);
75
#else
76
        return 0;
77
#endif
78
}
79
 
80
 
81
/*
82
 * Primitives to spin on a lock.  Needed only for SMP version ... so
83
 * somebody should start playing with one of those Sony NeWS stations.
84
 */
85
extern inline void get_buzz_lock(int *lock_ptr)
86
{
87
#ifdef __SMP__
88
        while (xchg(lock_ptr,1) != 0) ;
89
#endif
90
}
91
 
92
extern inline void give_buzz_lock(int *lock_ptr)
93
{
94
#ifdef __SMP__
95
        *lock_ptr = 0 ;
96
#endif
97
}
98
 
99
 
100
/*
101
 * Note! This is subtle. We jump to wake people up only if
102
 * the semaphore was negative (== somebody was waiting on it).
103
 * The default case (no contention) will result in NO
104
 * jumps for both down() and up().
105
 */
106
extern inline void up(struct semaphore * sem)
107
{
108
/* SIMON */
109
#if 0
110
        register struct semaphore *sem1 __asm__ ("%a1") = sem;
111
        __asm__ __volatile__(
112
                "| atomic up operation\n\t"
113
                "lea %%pc@(1f),%%a0\n\t"
114
                "addql #1,%0@\n\t"
115
                "jle " SYMBOL_NAME_STR(__up_wakeup) "\n"
116
                "1:"
117
                : /* no outputs */
118
                : "a" (sem1)
119
                : "%a0", "memory");
120
#endif
121
}
122
 
123
#endif

powered by: WebSVN 2.1.0

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