Re: deadlock avoidance?

Johannes Erdfelt (jerdfelt@sventech.com)
Tue, 7 Dec 1999 17:18:51 -0500


On Tue, Dec 07, 1999, Davide Libenzi <dlibenzi@maticad.it> wrote:
> Tuesday, December 07, 1999 8:50 PM
> Johannes Erdfelt <jerdfelt@sventech.com> wrote :
>
> Add another parameter to function that require the lock :
>
>
> spinlock_t lock = SPIN_LOCK_UNLOCKED;
> LIST_HEAD(list);
>
> void add_entry(struct foo *f, int need_lock)
> {
> unsigned long flags;
>
> if (need_lock)
> spin_lock_irqsave(&lock, flags);
> list_add(&f->list, &list);
> if (need_lock)
> spin_unlock_irqsave(&lock, flags);
> }
>
> void something(struct foo *f, int need_lock)
> {
> ...
> remove_entry(f, need_lock);
> ...
> add_entry(fnew, need_lock);
> ...
> }
>
>
> void interrupt(int irq, void *bar, struct pt_regs *regs)
> {
> struct list_head *tmp, *head = &list;
>
> spin_lock(&lock);
> tmp = head->next;
> while (tmp != head) {
> struct *foo = list_entry(tmp, struct foo, list);
>
> something(foo, 0);
> }
> spin_unlock(&lock);
> }

This is unfortunately too complicated. There's an API which other kernel
modules use which would need to be updated as well and passing that
information to the completion routine as well.

It would needlessly clutter the API.

Someone has worked up a different solution that *may* work but I don't
know if it has any race conditions. We'll see.

I always have solution #2 which is not too complicated, but more
complicated that I'd like.

JE

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