X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ffutex.c;h=332289924ab9ac3e1d88e54df78417175afa7238;hp=7f07b1118178c1795a197aba98007e74b196dfee;hb=cb8d0d245b5739e7493dcf27314f6e42615f14b1;hpb=6c1c0768320135c6936c371b09731851b508c023 diff --git a/src/common/futex.c b/src/common/futex.c index 7f07b1118..332289924 100644 --- a/src/common/futex.c +++ b/src/common/futex.c @@ -1,25 +1,13 @@ /* - * Copyright (C) 2011 - David Goulet - * Mathieu Desnoyers + * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 Mathieu Desnoyers * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include -#include #include #include #include @@ -55,8 +43,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); } @@ -84,10 +75,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"); } @@ -97,10 +101,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"); }