X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fconsumer.c;h=41ad46d8689338f3c27c3fc80fb12dd46bbdb53f;hp=87d5f34387befba860e31feefe0059a9c8c12f9b;hb=6addfa379ee608b20cfe5e15d135bcb6a9724e90;hpb=41ed8e47358244890326cb14dfae889ed0adb1ba diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 87d5f3438..41ad46d86 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -473,6 +473,7 @@ struct consumer_output *consumer_create_output(enum consumer_dst_type type) output->enabled = 1; output->type = type; output->net_seq_index = (uint64_t) -1ULL; + urcu_ref_init(&output->ref); output->socks = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); @@ -507,11 +508,10 @@ void consumer_destroy_output_sockets(struct consumer_output *obj) * * Should *NOT* be called with RCU read-side lock held. */ -void consumer_destroy_output(struct consumer_output *obj) +static void consumer_release_output(struct urcu_ref *ref) { - if (obj == NULL) { - return; - } + struct consumer_output *obj = + caa_container_of(ref, struct consumer_output, ref); consumer_destroy_output_sockets(obj); @@ -523,6 +523,27 @@ void consumer_destroy_output(struct consumer_output *obj) free(obj); } +/* + * Get the consumer_output object. + */ +void consumer_output_get(struct consumer_output *obj) +{ + urcu_ref_get(&obj->ref); +} + +/* + * Put the consumer_output object. + * + * Should *NOT* be called with RCU read-side lock held. + */ +void consumer_output_put(struct consumer_output *obj) +{ + if (!obj) { + return; + } + urcu_ref_put(&obj->ref, consumer_release_output); +} + /* * Copy consumer output and returned the newly allocated copy. * @@ -531,33 +552,28 @@ void consumer_destroy_output(struct consumer_output *obj) struct consumer_output *consumer_copy_output(struct consumer_output *obj) { int ret; - struct lttng_ht *tmp_ht_ptr; struct consumer_output *output; assert(obj); output = consumer_create_output(obj->type); if (output == NULL) { - goto error; + goto end; } - /* Avoid losing the HT reference after the memcpy() */ - tmp_ht_ptr = output->socks; - - memcpy(output, obj, sizeof(struct consumer_output)); - - /* Putting back the HT pointer and start copying socket(s). */ - output->socks = tmp_ht_ptr; - + output->enabled = obj->enabled; + output->net_seq_index = obj->net_seq_index; + memcpy(output->subdir, obj->subdir, PATH_MAX); + output->snapshot = obj->snapshot; + memcpy(&output->dst, &obj->dst, sizeof(output->dst)); ret = consumer_copy_sockets(output, obj); if (ret < 0) { - goto malloc_error; + goto error_put; } - -error: +end: return output; -malloc_error: - consumer_destroy_output(output); +error_put: + consumer_output_put(output); return NULL; }