Rename struct lttng_ust_channel_ops to struct lttng_ust_channel_buffer_ops
[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>
0466ac28 14#include <lttng/ringbuffer-context.h>
8173ec7c 15
fc80554e
MJ
16#include "context-internal.h"
17
8173ec7c 18static
daacdbfc 19size_t pthread_id_get_size(struct lttng_ust_ctx_field *field, size_t offset)
8173ec7c
MD
20{
21 size_t size = 0;
22
8de38cf7
MD
23 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
24 size += sizeof(unsigned long);
8173ec7c
MD
25 return size;
26}
27
28static
daacdbfc 29void pthread_id_record(struct lttng_ust_ctx_field *field,
4cfec15c 30 struct lttng_ust_lib_ring_buffer_ctx *ctx,
e7bc0ef6 31 struct lttng_ust_channel_buffer *chan)
8173ec7c
MD
32{
33 unsigned long pthread_id;
34
35 pthread_id = (unsigned long) pthread_self();
36 lib_ring_buffer_align_ctx(ctx, lttng_alignof(pthread_id));
37 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id));
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
MD
53 type = lttng_ust_create_type_integer(sizeof(unsigned long) * CHAR_BIT,
54 lttng_alignof(unsigned long) * CHAR_BIT,
55 lttng_is_signed_type(unsigned long),
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.036153 seconds and 4 git commands to generate.