lkml.org 
[lkml]   [2000]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subjectdown_trylock doesn't preserve irqstate

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/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.082 / U:22.976 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site