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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-ia64/] [semaphore.h] - Blame information for rev 1774

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

Line No. Rev Author Line
1 1275 phoenix
#ifndef _ASM_IA64_SEMAPHORE_H
2
#define _ASM_IA64_SEMAPHORE_H
3
 
4
/*
5
 * Copyright (C) 1998-2000 Hewlett-Packard Co
6
 * Copyright (C) 1998-2000 David Mosberger-Tang <davidm@hpl.hp.com>
7
 */
8
 
9
#include <linux/wait.h>
10
#include <linux/rwsem.h>
11
 
12
#include <asm/atomic.h>
13
 
14
struct semaphore {
15
        atomic_t count;
16
        int sleepers;
17
        wait_queue_head_t wait;
18
#if WAITQUEUE_DEBUG
19
        long __magic;           /* initialized by __SEM_DEBUG_INIT() */
20
#endif
21
};
22
 
23
#if WAITQUEUE_DEBUG
24
# define __SEM_DEBUG_INIT(name)         , (long) &(name).__magic
25
#else
26
# define __SEM_DEBUG_INIT(name)
27
#endif
28
 
29
#define __SEMAPHORE_INITIALIZER(name,count)                                     \
30
{                                                                               \
31
        ATOMIC_INIT(count), 0, __WAIT_QUEUE_HEAD_INITIALIZER((name).wait)        \
32
        __SEM_DEBUG_INIT(name)                                                  \
33
}
34
 
35
#define __MUTEX_INITIALIZER(name)       __SEMAPHORE_INITIALIZER(name,1)
36
 
37
#define __DECLARE_SEMAPHORE_GENERIC(name,count)                                 \
38
        struct semaphore name = __SEMAPHORE_INITIALIZER(name, count)
39
 
40
#define DECLARE_MUTEX(name)             __DECLARE_SEMAPHORE_GENERIC(name, 1)
41
#define DECLARE_MUTEX_LOCKED(name)      __DECLARE_SEMAPHORE_GENERIC(name, 0)
42
 
43
static inline void
44
sema_init (struct semaphore *sem, int val)
45
{
46
        *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
47
}
48
 
49
static inline void
50
init_MUTEX (struct semaphore *sem)
51
{
52
        sema_init(sem, 1);
53
}
54
 
55
static inline void
56
init_MUTEX_LOCKED (struct semaphore *sem)
57
{
58
        sema_init(sem, 0);
59
}
60
 
61
extern void __down (struct semaphore * sem);
62
extern int  __down_interruptible (struct semaphore * sem);
63
extern int  __down_trylock (struct semaphore * sem);
64
extern void __up (struct semaphore * sem);
65
 
66
/*
67
 * Atomically decrement the semaphore's count.  If it goes negative,
68
 * block the calling thread in the TASK_UNINTERRUPTIBLE state.
69
 */
70
static inline void
71
down (struct semaphore *sem)
72
{
73
#if WAITQUEUE_DEBUG
74
        CHECK_MAGIC(sem->__magic);
75
#endif
76
        if (atomic_dec_return(&sem->count) < 0)
77
                __down(sem);
78
}
79
 
80
/*
81
 * Atomically decrement the semaphore's count.  If it goes negative,
82
 * block the calling thread in the TASK_INTERRUPTIBLE state.
83
 */
84
static inline int
85
down_interruptible (struct semaphore * sem)
86
{
87
        int ret = 0;
88
 
89
#if WAITQUEUE_DEBUG
90
        CHECK_MAGIC(sem->__magic);
91
#endif
92
        if (atomic_dec_return(&sem->count) < 0)
93
                ret = __down_interruptible(sem);
94
        return ret;
95
}
96
 
97
static inline int
98
down_trylock (struct semaphore *sem)
99
{
100
        int ret = 0;
101
 
102
#if WAITQUEUE_DEBUG
103
        CHECK_MAGIC(sem->__magic);
104
#endif
105
        if (atomic_dec_return(&sem->count) < 0)
106
                ret = __down_trylock(sem);
107
        return ret;
108
}
109
 
110
static inline void
111
up (struct semaphore * sem)
112
{
113
#if WAITQUEUE_DEBUG
114
        CHECK_MAGIC(sem->__magic);
115
#endif
116
        if (atomic_inc_return(&sem->count) <= 0)
117
                __up(sem);
118
}
119
 
120
static inline int sem_getcount(struct semaphore *sem)
121
{
122
        return atomic_read(&sem->count);
123
}
124
 
125
#endif /* _ASM_IA64_SEMAPHORE_H */

powered by: WebSVN 2.1.0

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