1 |
/* |
/* Locks (sleep, pri lending, recursive). |
2 |
Copyright 1999, 2000, 2001 Johan Rydberg, jrydberg@opencores.org. |
Copyright 1999, 2000, 2001, 2002 Johan Rydberg, jrydberg@rtmk.org. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
301 |
if (wakeup) |
if (wakeup) |
302 |
thread_wakeup ((int) lock); |
thread_wakeup ((int) lock); |
303 |
} |
} |
304 |
|
|
305 |
|
/* Allow a thread that has a lock for write to acquire it |
306 |
|
recursively (for read, write, or update). */ |
307 |
|
void |
308 |
|
thread_lock_recursive_set (struct thread_lock *lock) |
309 |
|
{ |
310 |
|
spin_lock (&lock->interlock); |
311 |
|
if (! lock->want_write) |
312 |
|
{ |
313 |
|
panic ("lock_set_recursive: don't have write lock"); |
314 |
|
} |
315 |
|
lock->thread = THREAD_CURRENT (); |
316 |
|
spin_unlock (&lock->interlock); |
317 |
|
} |
318 |
|
|
319 |
|
/* Prevent a lock from being re-acquired. */ |
320 |
|
void |
321 |
|
thread_lock_recursive_clear (struct thread_lock *lock) |
322 |
|
{ |
323 |
|
spin_lock (&lock->interlock); |
324 |
|
if (lock->thread != THREAD_CURRENT ()) |
325 |
|
{ |
326 |
|
panic ("lock_clear_recursive: wrong thread"); |
327 |
|
} |
328 |
|
|
329 |
|
if (lock->recursion_depth == 0) |
330 |
|
lock->thread = (struct thread *) -1; |
331 |
|
spin_unlock (&lock->interlock); |
332 |
|
} |