relay: use urcu_ref_get_unless_zero
[lttng-tools.git] / src / bin / lttng-relayd / connection.c
index fce6c84d58c922f5d26491c62160ba49ab2577ef..e8c3d4bea5a50f2a28d69d88a94fb7b4744c168d 100644 (file)
@@ -17,7 +17,6 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <common/common.h>
 #include <urcu/rculist.h>
 
 bool connection_get(struct relay_connection *conn)
 {
-       bool has_ref = false;
-
-       pthread_mutex_lock(&conn->reflock);
-       if (conn->ref.refcount != 0) {
-               has_ref = true;
-               urcu_ref_get(&conn->ref);
-       }
-       pthread_mutex_unlock(&conn->reflock);
-
-       return has_ref;
+       return urcu_ref_get_unless_zero(&conn->ref);
 }
 
 struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht,
@@ -76,7 +66,6 @@ struct relay_connection *connection_create(struct lttcomm_sock *sock,
                PERROR("zmalloc relay connection");
                goto end;
        }
-       pthread_mutex_init(&conn->reflock, NULL);
        urcu_ref_init(&conn->ref);
        conn->type = type;
        conn->sock = sock;
@@ -132,9 +121,7 @@ static void connection_release(struct urcu_ref *ref)
 void connection_put(struct relay_connection *conn)
 {
        rcu_read_lock();
-       pthread_mutex_lock(&conn->reflock);
        urcu_ref_put(&conn->ref, connection_release);
-       pthread_mutex_unlock(&conn->reflock);
        rcu_read_unlock();
 }
 
This page took 0.024607 seconds and 5 git commands to generate.