Move to kernel style SPDX license identifiers
[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
b4051ad8 10#include <stddef.h>
8173ec7c 11#include <pthread.h>
4318ae1b
MD
12#include <lttng/ust-events.h>
13#include <lttng/ust-tracer.h>
14#include <lttng/ringbuffer-config.h>
8173ec7c
MD
15
16static
53569322 17size_t pthread_id_get_size(struct lttng_ctx_field *field, size_t offset)
8173ec7c
MD
18{
19 size_t size = 0;
20
8de38cf7
MD
21 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
22 size += sizeof(unsigned long);
8173ec7c
MD
23 return size;
24}
25
26static
27void pthread_id_record(struct lttng_ctx_field *field,
4cfec15c 28 struct lttng_ust_lib_ring_buffer_ctx *ctx,
7dd08bec 29 struct lttng_channel *chan)
8173ec7c
MD
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
77aa5901
MD
38static
39void pthread_id_get_value(struct lttng_ctx_field *field,
53569322 40 struct lttng_ctx_value *value)
77aa5901 41{
6e9ac4ae 42 value->u.s64 = (unsigned long) pthread_self();
77aa5901
MD
43}
44
8173ec7c
MD
45int 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;
218deb69
MD
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;
8173ec7c
MD
64 field->get_size = pthread_id_get_size;
65 field->record = pthread_id_record;
77aa5901 66 field->get_value = pthread_id_get_value;
b2cc986a 67 lttng_context_update(*ctx);
8173ec7c
MD
68 return 0;
69}
This page took 0.037247 seconds and 4 git commands to generate.