* 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,
PERROR("zmalloc relay connection");
goto end;
}
- pthread_mutex_init(&conn->reflock, NULL);
urcu_ref_init(&conn->ref);
conn->type = type;
conn->sock = sock;
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();
}