Move futex.c/.h to libcommon
authorDavid Goulet <dgoulet@efficios.com>
Tue, 8 May 2012 19:47:53 +0000 (15:47 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 8 May 2012 20:08:32 +0000 (16:08 -0400)
This is done so the future lttng-relayd and other possible binaries
could use it.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/futex.c [deleted file]
src/bin/lttng-sessiond/futex.h [deleted file]
src/bin/lttng-sessiond/main.c
src/common/Makefile.am
src/common/futex.c [new file with mode: 0644]
src/common/futex.h [new file with mode: 0644]

index 8748dd6bb915d6f8420872500c87661b9500f316..e450e4515e4adbf2d23805750aaf300676ad6fae 100644 (file)
@@ -12,7 +12,6 @@ lttng_sessiond_SOURCES = utils.c utils.h \
                        context.c context.h \
                        channel.c channel.h \
                        event.c event.h \
-                       futex.c futex.h \
                        shm.c shm.h \
                        session.c session.h \
                        modprobe.c modprobe.h kern-modules.h \
diff --git a/src/bin/lttng-sessiond/futex.c b/src/bin/lttng-sessiond/futex.c
deleted file mode 100644 (file)
index adfe66b..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
- *                       Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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.
- *
- * 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
-#include <limits.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include <urcu.h>
-#include <urcu/futex.h>
-
-#include <common/error.h>
-
-#include "futex.h"
-
-/*
- * This futex wait/wake scheme only works for N wakers / 1 waiters. Hence the
- * "nto1" added to all function signature.
- *
- * Please see wait_gp()/update_counter_and_wait() calls in urcu.c in the urcu
- * git tree for a detail example of this scheme being used. futex_async() is
- * the urcu wrapper over the futex() sycall.
- *
- * There is also a formal verification available in the git tree.
- *
- *   branch: formal-model
- *   commit id: 2a8044f3493046fcc8c67016902dc7beec6f026a
- *
- * Ref: git://git.lttng.org/userspace-rcu.git
- */
-
-/*
- * Update futex according to active or not. This scheme is used to wake every
- * libust waiting on the shared memory map futex hence the INT_MAX used in the
- * futex() call. If active, we set the value and wake everyone else we indicate
- * that we are gone (cleanup() case).
- */
-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);
-       } else {
-               uatomic_set(futex, 0);
-       }
-
-       DBG("Futex wait update active %d", active);
-}
-
-/*
- * Prepare futex.
- */
-void futex_nto1_prepare(int32_t *futex)
-{
-       uatomic_set(futex, -1);
-       cmm_smp_mb();
-
-       DBG("Futex n to 1 prepare done");
-}
-
-/*
- * Wait futex.
- */
-void futex_nto1_wait(int32_t *futex)
-{
-       cmm_smp_mb();
-
-       if (uatomic_read(futex) == -1) {
-               futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0);
-       }
-
-       DBG("Futex n to 1 wait done");
-}
-
-/*
- * Wake 1 futex.
- */
-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);
-       }
-
-       DBG("Futex n to 1 wake done");
-}
diff --git a/src/bin/lttng-sessiond/futex.h b/src/bin/lttng-sessiond/futex.h
deleted file mode 100644 (file)
index 9bdb2c1..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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.
- *
- * 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.
- */
-
-#ifndef _LTT_FUTEX_H
-#define _LTT_FUTEX_H
-
-void futex_wait_update(int32_t *futex, int active);
-void futex_nto1_prepare(int32_t *futex);
-void futex_nto1_wait(int32_t *futex);
-void futex_nto1_wake(int32_t *futex);
-
-#endif /* _LTT_FUTEX_H */
index 7327c3cb2262ddf4337b46c08f2d02160f1136e7..e1b3a828bc66f4ac68693ca55944cfbb8a9101c9 100644 (file)
@@ -33,7 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <urcu/futex.h>
 #include <urcu/uatomic.h>
 #include <unistd.h>
 #include <config.h>
 #include <common/defaults.h>
 #include <common/kernel-consumer/kernel-consumer.h>
 #include <common/ust-consumer/ust-consumer.h>
+#include <common/futex.h>
 
 #include "lttng-sessiond.h"
 #include "channel.h"
 #include "context.h"
 #include "event.h"
-#include "futex.h"
 #include "kernel.h"
 #include "modprobe.h"
 #include "shm.h"
index 5d79210b802819cd07e14e5b11338c16acfdca09..460f2a2de989bc65605f25ba67eb7102245191d4 100644 (file)
@@ -4,11 +4,11 @@ SUBDIRS = compat hashtable kernel-ctl sessiond-comm kernel-consumer ust-consumer
 
 AM_CFLAGS = -fno-strict-aliasing
 
-noinst_HEADERS = lttng-kernel.h defaults.h macros.h error.h
+noinst_HEADERS = lttng-kernel.h defaults.h macros.h error.h futex.h
 
 noinst_LTLIBRARIES = libcommon.la
 
-libcommon_la_SOURCES = runas.c runas.h common.h
+libcommon_la_SOURCES = runas.c runas.h common.h futex.c futex.h
 
 # Consumer library
 noinst_LTLIBRARIES += libconsumer.la
diff --git a/src/common/futex.c b/src/common/futex.c
new file mode 100644 (file)
index 0000000..adfe66b
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C)  2011 - David Goulet <david.goulet@polymtl.ca>
+ *                       Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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.
+ *
+ * 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
+#include <limits.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <urcu.h>
+#include <urcu/futex.h>
+
+#include <common/error.h>
+
+#include "futex.h"
+
+/*
+ * This futex wait/wake scheme only works for N wakers / 1 waiters. Hence the
+ * "nto1" added to all function signature.
+ *
+ * Please see wait_gp()/update_counter_and_wait() calls in urcu.c in the urcu
+ * git tree for a detail example of this scheme being used. futex_async() is
+ * the urcu wrapper over the futex() sycall.
+ *
+ * There is also a formal verification available in the git tree.
+ *
+ *   branch: formal-model
+ *   commit id: 2a8044f3493046fcc8c67016902dc7beec6f026a
+ *
+ * Ref: git://git.lttng.org/userspace-rcu.git
+ */
+
+/*
+ * Update futex according to active or not. This scheme is used to wake every
+ * libust waiting on the shared memory map futex hence the INT_MAX used in the
+ * futex() call. If active, we set the value and wake everyone else we indicate
+ * that we are gone (cleanup() case).
+ */
+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);
+       } else {
+               uatomic_set(futex, 0);
+       }
+
+       DBG("Futex wait update active %d", active);
+}
+
+/*
+ * Prepare futex.
+ */
+void futex_nto1_prepare(int32_t *futex)
+{
+       uatomic_set(futex, -1);
+       cmm_smp_mb();
+
+       DBG("Futex n to 1 prepare done");
+}
+
+/*
+ * Wait futex.
+ */
+void futex_nto1_wait(int32_t *futex)
+{
+       cmm_smp_mb();
+
+       if (uatomic_read(futex) == -1) {
+               futex_async(futex, FUTEX_WAIT, -1, NULL, NULL, 0);
+       }
+
+       DBG("Futex n to 1 wait done");
+}
+
+/*
+ * Wake 1 futex.
+ */
+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);
+       }
+
+       DBG("Futex n to 1 wake done");
+}
diff --git a/src/common/futex.h b/src/common/futex.h
new file mode 100644 (file)
index 0000000..9bdb2c1
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef _LTT_FUTEX_H
+#define _LTT_FUTEX_H
+
+void futex_wait_update(int32_t *futex, int active);
+void futex_nto1_prepare(int32_t *futex);
+void futex_nto1_wait(int32_t *futex);
+void futex_nto1_wake(int32_t *futex);
+
+#endif /* _LTT_FUTEX_H */
This page took 0.029559 seconds and 4 git commands to generate.