X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ffutex.c;h=2ae03b27d13c47b85510795ee9f657a1bc2c3cd6;hp=0b27a5bd7bb2b7360dbba351919da0c5a8a13c08;hb=890d8fe47755c3bad936389cf48ffa141cff41c9;hpb=90e535ef0d0433d31e805775f85e4d187b1cf82c diff --git a/src/common/futex.c b/src/common/futex.c index 0b27a5bd7..2ae03b27d 100644 --- a/src/common/futex.c +++ b/src/common/futex.c @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -54,8 +54,11 @@ 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); } @@ -83,10 +86,23 @@ 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"); } @@ -96,10 +112,13 @@ void futex_nto1_wait(int32_t *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"); }