Fix: pass private data to context callbacks
[lttng-ust.git] / liblttng-ust / lttng-ring-buffer-client-template.h
index dfc98ceeff8c4bc5044b35c771ef31043c985b92..a63786bc892ea93c990e7e3144a246f51c10a526 100644 (file)
 #define LTTNG_COMPACT_EVENT_BITS       5
 #define LTTNG_COMPACT_TSC_BITS         27
 
-enum app_ctx_mode {
-       APP_CTX_DISABLED,
-       APP_CTX_ENABLED,
-};
-
 /*
  * Keep the natural field alignment for _each field_ within this structure if
  * you ever add/remove a field from this header. Packed attribute is not used
@@ -83,7 +78,8 @@ void RING_BUFFER_MODE_TEMPLATE_TLS_FIXUP(void)
        asm volatile ("" : : "m" (URCU_TLS(private_ctx_stack)));
 }
 
-static inline uint64_t lib_ring_buffer_clock_read(struct lttng_ust_lib_ring_buffer_channel *chan)
+static inline uint64_t lib_ring_buffer_clock_read(
+               struct lttng_ust_lib_ring_buffer_channel *chan __attribute__((unused)))
 {
        return trace_clock_read64();
 }
@@ -102,8 +98,7 @@ size_t ctx_get_aligned_size(size_t offset, struct lttng_ust_ctx *ctx,
 }
 
 static inline
-void ctx_get_struct_size(struct lttng_ust_ctx *ctx, size_t *ctx_len,
-               enum app_ctx_mode mode)
+void ctx_get_struct_size(struct lttng_ust_ctx *ctx, size_t *ctx_len)
 {
        int i;
        size_t offset = 0;
@@ -112,62 +107,23 @@ void ctx_get_struct_size(struct lttng_ust_ctx *ctx, size_t *ctx_len,
                *ctx_len = 0;
                return;
        }
-       for (i = 0; i < ctx->nr_fields; i++) {
-               if (mode == APP_CTX_ENABLED) {
-                       offset += ctx->fields[i]->get_size(ctx->fields[i], offset);
-               } else {
-                       if (lttng_context_is_app(ctx->fields[i]->event_field->name)) {
-                               /*
-                                * Before UST 2.8, we cannot use the
-                                * application context, because we
-                                * cannot trust that the handler used
-                                * for get_size is the same used for
-                                * ctx_record, which would result in
-                                * corrupted traces when tracing
-                                * concurrently with application context
-                                * register/unregister.
-                                */
-                               offset += lttng_ust_dummy_get_size(ctx->fields[i], offset);
-                       } else {
-                               offset += ctx->fields[i]->get_size(ctx->fields[i], offset);
-                       }
-               }
-       }
+       for (i = 0; i < ctx->nr_fields; i++)
+               offset += ctx->fields[i].get_size(ctx->fields[i].priv, offset);
        *ctx_len = offset;
 }
 
 static inline
 void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx,
                struct lttng_ust_channel_buffer *chan,
-               struct lttng_ust_ctx *ctx,
-               enum app_ctx_mode mode)
+               struct lttng_ust_ctx *ctx)
 {
        int i;
 
        if (caa_likely(!ctx))
                return;
        lttng_ust_lib_ring_buffer_align_ctx(bufctx, ctx->largest_align);
-       for (i = 0; i < ctx->nr_fields; i++) {
-               if (mode == APP_CTX_ENABLED) {
-                       ctx->fields[i]->record(ctx->fields[i], bufctx, chan);
-               } else {
-                       if (lttng_context_is_app(ctx->fields[i]->event_field->name)) {
-                               /*
-                                * Before UST 2.8, we cannot use the
-                                * application context, because we
-                                * cannot trust that the handler used
-                                * for get_size is the same used for
-                                * ctx_record, which would result in
-                                * corrupted traces when tracing
-                                * concurrently with application context
-                                * register/unregister.
-                                */
-                               lttng_ust_dummy_record(ctx->fields[i], bufctx, chan);
-                       } else {
-                               ctx->fields[i]->record(ctx->fields[i], bufctx, chan);
-                       }
-               }
-       }
+       for (i = 0; i < ctx->nr_fields; i++)
+               ctx->fields[i].record(ctx->fields[i].priv, bufctx, chan);
 }
 
 /*
@@ -184,12 +140,13 @@ void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx,
  * contains.
  */
 static __inline__
-size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config,
-                                struct lttng_ust_lib_ring_buffer_channel *chan,
-                                size_t offset,
-                                size_t *pre_header_padding,
-                                struct lttng_ust_lib_ring_buffer_ctx *ctx,
-                                struct lttng_client_ctx *client_ctx)
+size_t record_header_size(
+               const struct lttng_ust_lib_ring_buffer_config *config __attribute__((unused)),
+               struct lttng_ust_lib_ring_buffer_channel *chan,
+               size_t offset,
+               size_t *pre_header_padding,
+               struct lttng_ust_lib_ring_buffer_ctx *ctx,
+               struct lttng_client_ctx *client_ctx)
 {
        struct lttng_ust_channel_buffer *lttng_chan = channel_get_private(chan);
        size_t orig_offset = offset;
@@ -297,8 +254,8 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con
                WARN_ON_ONCE(1);
        }
 
-       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx, APP_CTX_ENABLED);
-       ctx_record(ctx, lttng_chan, client_ctx->event_ctx, APP_CTX_ENABLED);
+       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx);
+       ctx_record(ctx, lttng_chan, client_ctx->event_ctx);
        lttng_ust_lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
 
        return;
@@ -371,8 +328,8 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
        default:
                WARN_ON_ONCE(1);
        }
-       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx, APP_CTX_ENABLED);
-       ctx_record(ctx, lttng_chan, client_ctx->event_ctx, APP_CTX_ENABLED);
+       ctx_record(ctx, lttng_chan, client_ctx->chan_ctx);
+       ctx_record(ctx, lttng_chan, client_ctx->event_ctx);
        lttng_ust_lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
 }
 
@@ -467,25 +424,35 @@ static void client_buffer_end(struct lttng_ust_lib_ring_buffer *buf, uint64_t ts
        header->ctx.events_discarded = records_lost;
 }
 
-static int client_buffer_create(struct lttng_ust_lib_ring_buffer *buf, void *priv,
-                               int cpu, const char *name, struct lttng_ust_shm_handle *handle)
+static int client_buffer_create(
+               struct lttng_ust_lib_ring_buffer *buf __attribute__((unused)),
+               void *priv __attribute__((unused)),
+               int cpu __attribute__((unused)),
+               const char *name __attribute__((unused)),
+               struct lttng_ust_shm_handle *handle __attribute__((unused)))
 {
        return 0;
 }
 
-static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf, void *priv, int cpu, struct lttng_ust_shm_handle *handle)
+static void client_buffer_finalize(
+               struct lttng_ust_lib_ring_buffer *buf __attribute__((unused)),
+               void *priv __attribute__((unused)),
+               int cpu __attribute__((unused)),
+               struct lttng_ust_shm_handle *handle __attribute__((unused)))
 {
 }
 
-static void client_content_size_field(const struct lttng_ust_lib_ring_buffer_config *config,
-                                     size_t *offset, size_t *length)
+static void client_content_size_field(
+               const struct lttng_ust_lib_ring_buffer_config *config __attribute__((unused)),
+               size_t *offset, size_t *length)
 {
        *offset = offsetof(struct packet_header, ctx.content_size);
        *length = sizeof(((struct packet_header *) NULL)->ctx.content_size);
 }
 
-static void client_packet_size_field(const struct lttng_ust_lib_ring_buffer_config *config,
-                                     size_t *offset, size_t *length)
+static void client_packet_size_field(
+               const struct lttng_ust_lib_ring_buffer_config *config __attribute__((unused)),
+               size_t *offset, size_t *length)
 {
        *offset = offsetof(struct packet_header, ctx.packet_size);
        *length = sizeof(((struct packet_header *) NULL)->ctx.packet_size);
@@ -567,7 +534,7 @@ static int client_packet_size(struct lttng_ust_lib_ring_buffer *buf,
        return 0;
 }
 
-static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf,
+static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf __attribute__((unused)),
                struct lttng_ust_lib_ring_buffer_channel *chan,
                uint64_t *stream_id)
 {
@@ -578,7 +545,8 @@ static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf,
        return 0;
 }
 
-static int client_current_timestamp(struct lttng_ust_lib_ring_buffer *buf,
+static int client_current_timestamp(
+               struct lttng_ust_lib_ring_buffer *buf  __attribute__((unused)),
                struct lttng_ust_lib_ring_buffer_channel *chan,
                uint64_t *ts)
 {
@@ -602,7 +570,7 @@ static int client_sequence_number(struct lttng_ust_lib_ring_buffer *buf,
 }
 
 static int client_instance_id(struct lttng_ust_lib_ring_buffer *buf,
-               struct lttng_ust_lib_ring_buffer_channel *chan,
+               struct lttng_ust_lib_ring_buffer_channel *chan __attribute__((unused)),
                uint64_t *id)
 {
        *id = buf->backend.cpu;
@@ -722,10 +690,8 @@ int lttng_event_reserve(struct lttng_ust_lib_ring_buffer_ctx *ctx)
        client_ctx.chan_ctx = lttng_ust_rcu_dereference(lttng_chan->priv->ctx);
        client_ctx.event_ctx = lttng_ust_rcu_dereference(event_recorder->priv->ctx);
        /* Compute internal size of context structures. */
-       ctx_get_struct_size(client_ctx.chan_ctx, &client_ctx.packet_context_len,
-                       APP_CTX_ENABLED);
-       ctx_get_struct_size(client_ctx.event_ctx, &client_ctx.event_context_len,
-                       APP_CTX_ENABLED);
+       ctx_get_struct_size(client_ctx.chan_ctx, &client_ctx.packet_context_len);
+       ctx_get_struct_size(client_ctx.event_ctx, &client_ctx.event_context_len);
 
        nesting = lib_ring_buffer_nesting_inc(&client_config);
        if (nesting < 0)
This page took 0.025765 seconds and 4 git commands to generate.