lkml.org 
[lkml]   [1999]   [Dec]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: deadlock avoidance?
    Date
    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);
    }

    Cheers,
    Davide.

    --
    "Debian, the Freedom in Freedom."



    -
    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:55    [W:0.022 / U:28.992 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site