2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <common/common.h>
23 #include <common/utils.h>
25 #include "ctf-trace.h"
27 static uint64_t last_relay_ctf_trace_id
;
30 * Try to destroy a ctf_trace object meaning that the refcount is decremented
31 * and checked if down to 0 which will free it.
33 void ctf_trace_try_destroy(struct ctf_trace
*obj
)
35 unsigned long ret_ref
;
41 ret_ref
= uatomic_add_return(&obj
->refcount
, -1);
43 DBG("Freeing ctf_trace %" PRIu64
, obj
->id
);
49 * Create and return an allocated ctf_trace object. NULL on error.
51 struct ctf_trace
*ctf_trace_create(void)
53 struct ctf_trace
*obj
;
55 obj
= zmalloc(sizeof(*obj
));
57 PERROR("ctf_trace alloc");
61 obj
->id
= ++last_relay_ctf_trace_id
;
62 DBG("Created ctf_trace %" PRIu64
, obj
->id
);
69 * Check if we can assign the ctf_trace id and metadata stream to one or all
70 * the streams with the same path_name (our unique ID for ctf traces).
72 * The given stream MUST be new and NOT visible (in any hash table).
74 void ctf_trace_assign(struct lttng_ht
*ht
, struct relay_stream
*stream
)
76 struct lttng_ht_iter iter
;
77 struct relay_stream
*tmp_stream
;
83 cds_lfht_for_each_entry_duplicate(ht
->ht
,
84 ht
->hash_fct((void *) stream
->path_name
, lttng_ht_seed
),
85 ht
->match_fct
, (void *) stream
->path_name
,
86 &iter
.iter
, tmp_stream
, ctf_trace_node
.node
) {
87 if (stream
->metadata_flag
) {
89 * The new stream is the metadata stream for this trace,
90 * assign the ctf_trace pointer to all the streams in
93 pthread_mutex_lock(&tmp_stream
->lock
);
94 tmp_stream
->ctf_trace
= stream
->ctf_trace
;
95 uatomic_inc(&tmp_stream
->ctf_trace
->refcount
);
96 pthread_mutex_unlock(&tmp_stream
->lock
);
97 DBG("Assigned ctf_trace %" PRIu64
" to stream %" PRIu64
,
98 tmp_stream
->ctf_trace
->id
, tmp_stream
->stream_handle
);
99 } else if (tmp_stream
->ctf_trace
) {
101 * The ctf_trace already exists for this bucket,
102 * just assign the pointer to the new stream and exit.
104 stream
->ctf_trace
= tmp_stream
->ctf_trace
;
105 uatomic_inc(&stream
->ctf_trace
->refcount
);
106 DBG("Assigned ctf_trace %" PRIu64
" to stream %" PRIu64
,
107 tmp_stream
->ctf_trace
->id
, tmp_stream
->stream_handle
);
111 * We don't know yet the ctf_trace ID (no metadata has been added),
112 * so leave it there until the metadata stream arrives.
This page took 0.033157 seconds and 5 git commands to generate.