initialize correctly urcu library
[ust.git] / libust / tracectl.c
index 277dbcd75d773f31f9c19f1056d49715d7dfabde..97ab2eb1fb768433c4561733dcfded9b25cee235 100644 (file)
@@ -1,3 +1,20 @@
+/* Copyright (C) 2009  Pierre-Marc Fournier
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdint.h>
@@ -9,6 +26,8 @@
 #include <fcntl.h>
 #include <poll.h>
 
+#include <urcu.h>
+
 #include "marker.h"
 #include "tracer.h"
 #include "localerr.h"
@@ -89,8 +108,13 @@ void do_command(struct tracecmd *cmd)
 {
 }
 
-void receive_commands()
+/* This needs to be called whenever a new thread is created. It notifies
+ * liburcu of the new thread.
+ */
+
+void ust_register_thread(void)
 {
+       rcu_register_thread();
 }
 
 int fd_notif = -1;
@@ -147,7 +171,8 @@ void process_blocked_consumers(void)
                idx++;
        }
 
-       result = poll(fds, n_fds, 0);
+       while((result = poll(fds, n_fds, 0)) == -1 && errno == EINTR)
+               /* nothing */;
        if(result == -1) {
                PERROR("poll");
                return;
@@ -206,6 +231,8 @@ void *listener_main(void *p)
 {
        int result;
 
+       ust_register_thread();
+
        DBG("LISTENER");
 
        for(;;) {
@@ -785,6 +812,12 @@ static void auto_probe_connect(struct marker *m)
 
 static void __attribute__((constructor(101))) init0()
 {
+       /* Initialize RCU in case the constructor order is not good. */
+       urcu_init();
+
+       /* It is important to do this before events start to be generated. */
+       ust_register_thread();
+
        DBG("UST_AUTOPROBE constructor");
        if(getenv("UST_AUTOPROBE")) {
                marker_set_new_marker_cb(auto_probe_connect);
This page took 0.023435 seconds and 4 git commands to generate.