1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* Copyright (c) 1996-1999 The University of Utah and the Flux Group.
*
* This file is part of the OSKit Linux Glue Libraries, which are free
* software, also known as "open source;" you can redistribute them and/or
* modify them under the terms of the GNU General Public License (GPL),
* version 2, as published by the Free Software Foundation (FSF).
*
* The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
* received a copy of the GPL along with the OSKit; see the file COPYING. If
* not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
*/
/*
* Linux scheduler support.
*
* NOTE: These routines must carefully preserve the
* caller's interrupt flag.
*/
#include <linux/sched.h>
#include <asm/atomic.h>
#include "osenv.h"
/*
* Read the discussion in the linux source. Should the spinlock be under SMP?
*/
spinlock_t semaphore_wake_lock = SPIN_LOCK_UNLOCKED;
void
__down(struct semaphore *sem)
{
struct task_struct *cur = current;
struct wait_queue wait = { cur, NULL };
unsigned long flags;
save_flags(flags);
cli();
__add_wait_queue(&sem->wait, &wait);
while (1) {
spin_lock(&semaphore_wake_lock);
if (sem->waking > 0) {
sem->waking--;
spin_unlock(&semaphore_wake_lock);
break;
}
spin_unlock(&semaphore_wake_lock);
osenv_sleep_init(&cur->sleeprec);
osenv_sleep(&cur->sleeprec);
}
__remove_wait_queue(&sem->wait, &wait);
current = cur;
restore_flags(flags);
}
void
__up(struct semaphore *sem)
{
unsigned long flags;
save_flags(flags);
cli();
spin_lock(&semaphore_wake_lock);
if (atomic_read(&sem->count) <= 0)
sem->waking++;
spin_unlock(&semaphore_wake_lock);
restore_flags(flags);
wake_up(&sem->wait);
}
static void
__sleep_on(struct wait_queue **q, int interruptible)
{
struct task_struct *cur = current;
struct wait_queue wait = { cur, NULL };
if (!q)
return;
osenv_sleep_init(&cur->sleeprec);
add_wait_queue(q, &wait);
osenv_sleep(&cur->sleeprec);
current = cur;
remove_wait_queue(q, &wait);
current = cur;
}
void
sleep_on(struct wait_queue **q)
{
__sleep_on(q, 0);
}
void
interruptible_sleep_on(struct wait_queue **q)
{
__sleep_on(q, 1);
}
void
__wake_up(struct wait_queue **q, unsigned int mode)
{
struct wait_queue *next;
struct wait_queue *head;
if (!q || !(next = *q))
return;
head = WAIT_QUEUE_HEAD(q);
while (next != head) {
struct task_struct *p = next->task;
next = next->next;
if (p != NULL) {
osenv_wakeup(&p->sleeprec, OSENV_SLEEP_WAKEUP);
}
if (!next)
panic("wait_queue is bad");
}
}
void
__wait_on_buffer(struct buffer_head *bh)
{
struct task_struct *cur = current;
struct wait_queue wait = { cur, NULL };
unsigned flags;
flags = linux_save_flags();
linux_cli();
__add_wait_queue(&bh->b_wait, &wait);
while (buffer_locked(bh)) {
osenv_sleep_init(&cur->sleeprec);
osenv_sleep(&cur->sleeprec);
}
current = cur;
__remove_wait_queue(&bh->b_wait, &wait);
linux_restore_flags(flags);
current = cur;
}
void
unlock_buffer(struct buffer_head *bh)
{
clear_bit (BH_Lock, &bh->b_state);
wake_up(&bh->b_wait);
}
/*
* schedule() should never be called in the oskit since we have
* no resource contention.
*/
void
schedule()
{
panic("SCHEDULE CALLED!\n");
}
|