lkml.org 
[lkml]   [2012]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V2] UBI: add ubi_lnum_purge function to clear work queue for a lnum
> Take the work_sem at the beginning. Release at the very end.
>
> Then you can do something like this:
>
> int found = 1;
>
> while (found) {
> found = 0;
>
> spin_lock(&ubi->wl_lock);
> list_for_each_entry(wrk, tmp, &ubi->works, list) {
> if (wrk->lnum == lnum) {
> list_del(&wrk->list);
> ubi->works_count -= 1;
> ubi_assert(ubi->works_count >= 0);
> spin_unlock(&ubi->wl_lock);
>
> err = wrk->func(ubi, wrk, 0);
> if (err)
> return err;
>
> spin_lock(&ubi->wl_lock);
> found = 1;
> break;
> }
> spin_unlock(&ubi->wl_lock);
> }
>


If I use list_for_each_entry_safe(), it protects against deleting as it
iterates. If I take the work_sem first, is it okay to do a simple
traversal instead of one traversal per removed item? Even if another
thread adds new work for the same vol_id/lnum, its okay, because the
caller of this function only cares about vol_id/lnums erasures that
it knows are currently on the worklist.

Cheers,
Joel Reardon


\
 
 \ /
  Last update: 2012-05-19 12:21    [W:0.070 / U:1.904 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site