fix: string constants (-Wwrite-strings)
[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
daacdbfc 20size_t pthread_id_get_size(struct lttng_ust_ctx_field *field, size_t offset)
8173ec7c
MD
21{
22 size_t size = 0;
23
dc325c1d 24 size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(unsigned long));
8de38cf7 25 size += sizeof(unsigned long);
8173ec7c
MD
26 return size;
27}
28
29static
daacdbfc 30void pthread_id_record(struct lttng_ust_ctx_field *field,
4cfec15c 31 struct lttng_ust_lib_ring_buffer_ctx *ctx,
e7bc0ef6 32 struct lttng_ust_channel_buffer *chan)
8173ec7c
MD
33{
34 unsigned long pthread_id;
35
36 pthread_id = (unsigned long) pthread_self();
8936b6c0 37 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id), lttng_ust_rb_alignof(pthread_id));
8173ec7c
MD
38}
39
77aa5901 40static
daacdbfc
MD
41void pthread_id_get_value(struct lttng_ust_ctx_field *field,
42 struct lttng_ust_ctx_value *value)
77aa5901 43{
6e9ac4ae 44 value->u.s64 = (unsigned long) pthread_self();
77aa5901
MD
45}
46
daacdbfc 47int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx)
8173ec7c 48{
daacdbfc 49 struct lttng_ust_ctx_field *field;
a084756d
MD
50 struct lttng_ust_type_common *type;
51 int ret;
8173ec7c 52
a084756d 53 type = lttng_ust_create_type_integer(sizeof(unsigned long) * CHAR_BIT,
dc325c1d 54 lttng_ust_rb_alignof(unsigned long) * CHAR_BIT,
eae3c729 55 lttng_ust_is_signed_type(unsigned long),
a084756d
MD
56 BYTE_ORDER, 10);
57 if (!type)
8173ec7c 58 return -ENOMEM;
a084756d
MD
59 field = lttng_append_context(ctx);
60 if (!field) {
61 ret = -ENOMEM;
62 goto error_context;
63 }
8173ec7c 64 if (lttng_find_context(*ctx, "pthread_id")) {
a084756d
MD
65 ret = -EEXIST;
66 goto error_find_context;
8173ec7c 67 }
a084756d
MD
68 field->event_field->name = strdup("pthread_id");
69 if (!field->event_field->name) {
70 ret = -ENOMEM;
71 goto error_name;
72 }
73 field->event_field->type = type;
8173ec7c
MD
74 field->get_size = pthread_id_get_size;
75 field->record = pthread_id_record;
77aa5901 76 field->get_value = pthread_id_get_value;
b2cc986a 77 lttng_context_update(*ctx);
8173ec7c 78 return 0;
a084756d
MD
79
80error_name:
81error_find_context:
82 lttng_remove_context_field(ctx, field);
83error_context:
84 lttng_ust_destroy_type(type);
85 return ret;
8173ec7c 86}
This page took 0.035487 seconds and 4 git commands to generate.