One problem we encountered in using down_trylock
is that __down_trylock() uses spin_lock_irq() and spin_unlock_irq(),
which does not preserve the interrupt state of the
caller. So, when down_trylock() is called from a
piece of code that has interrupts disabled, on return
from down_trylock() interrupts would always be enabled.
One solution is the following patch which uses
_irqsave/_irqrestore versions of spinlock. The patch
solves a nasty deadlock (double-trip) in the XFS code.
Please let me know if you have any comments.
thanks,
ananth.
-----------------
--- /usr/tmp/p_rdiff_xrKkbe/semaphore.c Fri Feb 25 14:26:04 2000
+++ /build2/ananth/slinx23-xfs/linux/arch/i386/kernel/semaphore.c Fri Feb
25 01:03:24 2000
@@ -149,9 +149,9 @@
*/
int __down_trylock(struct semaphore * sem)
{
- int sleepers;
+ int sleepers, flags;
- spin_lock_irq(&semaphore_lock);
+ spin_lock_irqsave(&semaphore_lock, flags);
sleepers = sem->sleepers + 1;
sem->sleepers = 0;
@@ -162,7 +162,7 @@
if (!atomic_add_negative(sleepers, &sem->count))
wake_up(&sem->wait);
- spin_unlock_irq(&semaphore_lock);
+ spin_unlock_irqrestore(&semaphore_lock, flags);
return 1;
}
------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Tue Feb 29 2000 - 21:00:14 EST