2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <sys/syscall.h>
24 #include <urcu/futex.h>
26 #include <common/common.h>
31 * This futex wait/wake scheme only works for N wakers / 1 waiters. Hence the
32 * "nto1" added to all function signature.
34 * Please see wait_gp()/update_counter_and_wait() calls in urcu.c in the urcu
35 * git tree for a detail example of this scheme being used. futex_async() is
36 * the urcu wrapper over the futex() sycall.
38 * There is also a formal verification available in the git tree.
40 * branch: formal-model
41 * commit id: 2a8044f3493046fcc8c67016902dc7beec6f026a
43 * Ref: git://git.lttng.org/userspace-rcu.git
47 * Update futex according to active or not. This scheme is used to wake every
48 * libust waiting on the shared memory map futex hence the INT_MAX used in the
49 * futex() call. If active, we set the value and wake everyone else we indicate
50 * that we are gone (cleanup() case).
53 void futex_wait_update(int32_t *futex
, int active
)
56 uatomic_set(futex
, 1);
57 futex_async(futex
, FUTEX_WAKE
,
58 INT_MAX
, NULL
, NULL
, 0);
60 uatomic_set(futex
, 0);
63 DBG("Futex wait update active %d", active
);
70 void futex_nto1_prepare(int32_t *futex
)
72 uatomic_set(futex
, -1);
75 DBG("Futex n to 1 prepare done");
82 void futex_nto1_wait(int32_t *futex
)
86 if (uatomic_read(futex
) == -1) {
87 futex_async(futex
, FUTEX_WAIT
, -1, NULL
, NULL
, 0);
90 DBG("Futex n to 1 wait done");
97 void futex_nto1_wake(int32_t *futex
)
99 if (caa_unlikely(uatomic_read(futex
) == -1)) {
100 uatomic_set(futex
, 0);
101 futex_async(futex
, FUTEX_WAKE
, 1, NULL
, NULL
, 0);
104 DBG("Futex n to 1 wake done");
This page took 0.035568 seconds and 5 git commands to generate.