X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-context-vtid.c;h=80661f632d8c0305ad059706e8d6528668420a0c;hb=70b36cd63f75c305d948bbce2177d834df5d8323;hp=4b1da4f8e9b78541473f3e838352e04ac4461679;hpb=8c90a710949a214d87084ff67fc85f284bc93ef2;p=lttng-ust.git diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index 4b1da4f8..80661f63 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define _LGPL_SOURCE #include #include #include @@ -42,11 +43,11 @@ static DEFINE_URCU_TLS(pid_t, cached_vtid); */ void lttng_context_vtid_reset(void) { - URCU_TLS(cached_vtid) = 0; + CMM_STORE_SHARED(URCU_TLS(cached_vtid), 0); } static -size_t vtid_get_size(size_t offset) +size_t vtid_get_size(struct lttng_ctx_field *field, size_t offset) { size_t size = 0; @@ -55,16 +56,35 @@ size_t vtid_get_size(size_t offset) return size; } +static inline +pid_t wrapper_getvtid(void) +{ + pid_t vtid; + + vtid = CMM_LOAD_SHARED(URCU_TLS(cached_vtid)); + if (caa_unlikely(!vtid)) { + vtid = gettid(); + CMM_STORE_SHARED(URCU_TLS(cached_vtid), vtid); + } + return vtid; +} + static void vtid_record(struct lttng_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { - if (caa_unlikely(!URCU_TLS(cached_vtid))) - URCU_TLS(cached_vtid) = gettid(); - lib_ring_buffer_align_ctx(ctx, lttng_alignof(URCU_TLS(cached_vtid))); - chan->ops->event_write(ctx, &URCU_TLS(cached_vtid), - sizeof(URCU_TLS(cached_vtid))); + pid_t vtid = wrapper_getvtid(); + + lib_ring_buffer_align_ctx(ctx, lttng_alignof(vtid)); + chan->ops->event_write(ctx, &vtid, sizeof(vtid)); +} + +static +void vtid_get_value(struct lttng_ctx_field *field, + struct lttng_ctx_value *value) +{ + value->u.s64 = wrapper_getvtid(); } int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) @@ -88,6 +108,8 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) field->event_field.type.u.basic.integer.encoding = lttng_encode_none; field->get_size = vtid_get_size; field->record = vtid_record; + field->get_value = vtid_get_value; + lttng_context_update(*ctx); return 0; }