Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust / lttng-context-pthread-id.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2009-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng UST pthread_id context.
7 */
8
9 #define _LGPL_SOURCE
10 #include <stddef.h>
11 #include <pthread.h>
12 #include <lttng/ust-events.h>
13 #include <lttng/ust-tracer.h>
14 #include <lttng/ringbuffer-config.h>
15
16 static
17 size_t pthread_id_get_size(struct lttng_ctx_field *field, size_t offset)
18 {
19 size_t size = 0;
20
21 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
22 size += sizeof(unsigned long);
23 return size;
24 }
25
26 static
27 void pthread_id_record(struct lttng_ctx_field *field,
28 struct lttng_ust_lib_ring_buffer_ctx *ctx,
29 struct lttng_channel *chan)
30 {
31 unsigned long pthread_id;
32
33 pthread_id = (unsigned long) pthread_self();
34 lib_ring_buffer_align_ctx(ctx, lttng_alignof(pthread_id));
35 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id));
36 }
37
38 static
39 void pthread_id_get_value(struct lttng_ctx_field *field,
40 struct lttng_ctx_value *value)
41 {
42 value->u.s64 = (unsigned long) pthread_self();
43 }
44
45 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx)
46 {
47 struct lttng_ctx_field *field;
48
49 field = lttng_append_context(ctx);
50 if (!field)
51 return -ENOMEM;
52 if (lttng_find_context(*ctx, "pthread_id")) {
53 lttng_remove_context_field(ctx, field);
54 return -EEXIST;
55 }
56 field->event_field.name = "pthread_id";
57 field->event_field.type.atype = atype_integer;
58 field->event_field.type.u.integer.size = sizeof(unsigned long) * CHAR_BIT;
59 field->event_field.type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT;
60 field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned long);
61 field->event_field.type.u.integer.reverse_byte_order = 0;
62 field->event_field.type.u.integer.base = 10;
63 field->event_field.type.u.integer.encoding = lttng_encode_none;
64 field->get_size = pthread_id_get_size;
65 field->record = pthread_id_record;
66 field->get_value = pthread_id_get_value;
67 lttng_context_update(*ctx);
68 return 0;
69 }
This page took 0.030084 seconds and 4 git commands to generate.