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
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <sys/syscall.h>
24 #include <urcu/futex.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
49 void futex_nto1_prepare(int32_t *futex
)
51 uatomic_set(futex
, -1);
54 DBG("Futex n to 1 prepare done");
60 void futex_nto1_wait(int32_t *futex
)
64 if (uatomic_read(futex
) == -1) {
65 futex_async(futex
, FUTEX_WAIT
, -1, NULL
, NULL
, 0);
68 DBG("Futex n to 1 wait done");
74 void futex_nto1_wake(int32_t *futex
)
76 if (unlikely(uatomic_read(futex
) == -1)) {
77 uatomic_set(futex
, 0);
78 futex_async(futex
, FUTEX_WAKE
, 1, NULL
, NULL
, 0);
81 DBG("Futex n to 1 wake done");
This page took 0.030045 seconds and 4 git commands to generate.