Fix: pass private data to context callbacks
[lttng-ust.git] / liblttng-ust / lttng-context-pthread-id.c
CommitLineData
8173ec7c 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
8173ec7c 3 *
e92f3e28
MD
4 * Copyright (C) 2009-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
c0c0989a 6 * LTTng UST pthread_id context.
8173ec7c
MD
7 */
8
3fbec7dc 9#define _LGPL_SOURCE
9af5d97a 10#include <limits.h>
b4051ad8 11#include <stddef.h>
8173ec7c 12#include <pthread.h>
4318ae1b
MD
13#include <lttng/ust-events.h>
14#include <lttng/ust-tracer.h>
0466ac28 15#include <lttng/ringbuffer-context.h>
8173ec7c 16
fc80554e
MJ
17#include "context-internal.h"
18
8173ec7c 19static
4e48b5d2 20size_t pthread_id_get_size(void *priv __attribute__((unused)),
2208d8b5 21 size_t offset)
8173ec7c
MD
22{
23 size_t size = 0;
24
dc325c1d 25 size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(unsigned long));
8de38cf7 26 size += sizeof(unsigned long);
8173ec7c
MD
27 return size;
28}
29
30static
4e48b5d2 31void pthread_id_record(void *priv __attribute__((unused)),
4cfec15c 32 struct lttng_ust_lib_ring_buffer_ctx *ctx,
e7bc0ef6 33 struct lttng_ust_channel_buffer *chan)
8173ec7c
MD
34{
35 unsigned long pthread_id;
36
37 pthread_id = (unsigned long) pthread_self();
8936b6c0 38 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id), lttng_ust_rb_alignof(pthread_id));
8173ec7c
MD
39}
40
77aa5901 41static
4e48b5d2 42void pthread_id_get_value(void *priv __attribute__((unused)),
daacdbfc 43 struct lttng_ust_ctx_value *value)
77aa5901 44{
6e9ac4ae 45 value->u.s64 = (unsigned long) pthread_self();
77aa5901
MD
46}
47
4e48b5d2
MD
48static const struct lttng_ust_ctx_field *ctx_field = lttng_ust_static_ctx_field(
49 lttng_ust_static_event_field("pthread_id",
50 lttng_ust_static_type_integer(sizeof(unsigned long) * CHAR_BIT,
51 lttng_ust_rb_alignof(unsigned long) * CHAR_BIT,
52 lttng_ust_is_signed_type(unsigned long),
53 BYTE_ORDER, 10),
54 false, false),
55 pthread_id_get_size,
56 pthread_id_record,
57 pthread_id_get_value,
58 NULL, NULL);
59
daacdbfc 60int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx)
8173ec7c 61{
a084756d 62 int ret;
8173ec7c 63
4e48b5d2 64 if (lttng_find_context(*ctx, ctx_field->event_field->name)) {
a084756d
MD
65 ret = -EEXIST;
66 goto error_find_context;
8173ec7c 67 }
4e48b5d2
MD
68 ret = lttng_ust_context_append(ctx, ctx_field);
69 if (ret)
70 return ret;
8173ec7c 71 return 0;
a084756d 72
a084756d 73error_find_context:
a084756d 74 return ret;
8173ec7c 75}
This page took 0.038127 seconds and 4 git commands to generate.