futex.2: simplify example

Do not duplicate coding.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Heinrich Schuchardt 2015-02-28 02:25:47 +01:00 committed by Michael Kerrisk
parent 92a4669004
commit 63ad44cb92
1 changed files with 5 additions and 14 deletions

View File

@ -1582,24 +1582,15 @@ fwait(int *futexp)
machine\-language instructions. For further information, see
the GCC Manual. */
/* Maybe the futex is already available: */
if (__sync_bool_compare_and_swap(futexp, 1, 0))
return;
/* No; we must wait for the futex value to be changed */
while (1) {
s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
if (s == \-1 && errno != EAGAIN)
errExit("futex\-FUTEX_WAIT");
/* Is the futex now available? */
/* Is the futex available? */
if (__sync_bool_compare_and_swap(futexp, 1, 0))
break; /* Yes */
/* Futex is still not available; wait again */
/* Futex is not available; wait */
s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
if (s == \-1 && errno != EAGAIN)
errExit("futex\-FUTEX_WAIT");
}
}