PERFORCE change 104029 for review
John Baldwin
jhb at freebsd.org
Tue Aug 15 15:30:28 UTC 2006
On Tuesday 15 August 2006 10:07, Roman Divacky wrote:
> http://perforce.freebsd.org/chv.cgi?CH=104029
>
> Change 104029 by rdivacky at rdivacky_witten on 2006/08/15 14:06:41
>
> Protect against racing concurent creation in futex_get()
>
> Pointed out by: jhb
>
> Affected files ...
>
> .. //depot/projects/soc2006/rdivacky_linuxolator/compat/linux/linux_futex.c#24
edit
>
> Differences ...
>
>
==== //depot/projects/soc2006/rdivacky_linuxolator/compat/linux/linux_futex.c#24
(text+ko) ====
>
> @@ -342,13 +342,13 @@
> if (locked == FUTEX_UNLOCKED)
> FUTEX_UNLOCK;
>
> + if (locked == FUTEX_UNLOCKED)
> + FUTEX_LOCK;
Looks like you should collapse the lock/unlock. However, it's probably best
to use mutexes instead of sx locks, and to instead do something like this:
lock();
if (item in list) {
item->ref++;
unlock();
return (item);
}
unlock();
new_item = new_item();
lock();
if (item in list) {
item->ref++;
unlock();
free(new_item);
return (item);
}
insert new_item
new_item->ref++;
unlock();
return (new_item)
--
John Baldwin
More information about the p4-projects
mailing list