Linux-kernel mailing list archive 1999-36,: Re: Help with semaphores/locks, anyone?

# Re: Help with semaphores/locks, anyone?

Alan Cox (alan@lxorguk.ukuu.org.uk)
Thu, 9 Sep 1999 11:34:43 +0100 (BST)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Chris Smith: "Re: Shortening the Development Cycle..."
- Previous message: Roman Mitnitski: "Help with semaphores/locks, anyone?"
- Next in thread: Thomas S. Iversen: "Redhat 6.0 bootdisk to Athlon"
- Reply: Thomas S. Iversen: "Redhat 6.0 bootdisk to Athlon"

> struct semaphore my_sem=MUTEX;
>
> ioctl_handler()
> {
> down(&my_sem);
> ...
> up(&my_sem);
> }
>
> in_the_interrupt()
> {
> down(&my_sem);
> ...
> up(&my_sem);
> }

You cannot sleep i nan interrupt

> When I disable interrupts in the ioctl_handler()
> the crash goes away, but I would rather avoid disabling all
> interrupts (for performance reasons), I only need to protect the
> access to my variables.

You need to disable local interrupts at least to avoid the deadlock where
you take an interrupt in your ioctl handler when holding the lock.

You want spin_lock_irqsave /spin_unlock_irqrestore for the ioctl and
spin_lock/spin_unlock for the IRQ handler

-
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/

- Next message: Chris Smith: "Re: Shortening the Development Cycle..."
- Previous message: Roman Mitnitski: "Help with semaphores/locks, anyone?"
- Next in thread: Thomas S. Iversen: "Redhat 6.0 bootdisk to Athlon"
- Reply: Thomas S. Iversen: "Redhat 6.0 bootdisk to Athlon"