X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ffutex.c;h=384e957a22d0406751c13dd03f02edd22bb0b768;hp=adfe66b1c29feb3295949253f315819c8d110d92;hb=d186e4cbbca201936132f3b6aad1710e35dec373;hpb=50c8f4840cc0cf140c760159c8705592d6b434ea diff --git a/src/common/futex.c b/src/common/futex.c index adfe66b1c..384e957a2 100644 --- a/src/common/futex.c +++ b/src/common/futex.c @@ -16,14 +16,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE +#define _LGPL_SOURCE #include -#include #include #include #include -#include +#include #include "futex.h" @@ -49,12 +48,16 @@ * futex() call. If active, we set the value and wake everyone else we indicate * that we are gone (cleanup() case). */ +LTTNG_HIDDEN void futex_wait_update(int32_t *futex, int active) { if (active) { uatomic_set(futex, 1); - futex_async(futex, FUTEX_WAKE, - INT_MAX, NULL, NULL, 0); + if (futex_async(futex, FUTEX_WAKE, + INT_MAX, NULL, NULL, 0) < 0) { + PERROR("futex_async"); + abort(); + } } else { uatomic_set(futex, 0); } @@ -65,6 +68,7 @@ void futex_wait_update(int32_t *futex, int active) /* * Prepare futex. */ +LTTNG_HIDDEN void futex_nto1_prepare(int32_t *futex) { uatomic_set(futex, -1); @@ -76,26 +80,44 @@ void futex_nto1_prepare(int32_t *futex) /* * Wait futex. */ +LTTNG_HIDDEN void futex_nto1_wait(int32_t *futex) { cmm_smp_mb(); - if (uatomic_read(futex) == -1) { - futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0); + if (uatomic_read(futex) != -1) + goto end; + while (futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0)) { + switch (errno) { + case EWOULDBLOCK: + /* Value already changed. */ + goto end; + case EINTR: + /* Retry if interrupted by signal. */ + break; /* Get out of switch. */ + default: + /* Unexpected error. */ + PERROR("futex_async"); + abort(); + } } - +end: DBG("Futex n to 1 wait done"); } /* * Wake 1 futex. */ +LTTNG_HIDDEN void futex_nto1_wake(int32_t *futex) { - if (caa_unlikely(uatomic_read(futex) == -1)) { - uatomic_set(futex, 0); - futex_async(futex, FUTEX_WAKE, 1, NULL, NULL, 0); + if (caa_unlikely(uatomic_read(futex) != -1)) + goto end; + uatomic_set(futex, 0); + if (futex_async(futex, FUTEX_WAKE, 1, NULL, NULL, 0) < 0) { + PERROR("futex_async"); + abort(); } - +end: DBG("Futex n to 1 wake done"); }