Namespace remaining symbols in lttng/ringbuffer-context.h
[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 <limits.h>
11 #include <stddef.h>
12 #include <pthread.h>
13 #include <lttng/ust-events.h>
14 #include <lttng/ust-tracer.h>
15 #include <lttng/ringbuffer-context.h>
16
17 #include "context-internal.h"
18
19 static
20 size_t pthread_id_get_size(struct lttng_ust_ctx_field *field, size_t offset)
21 {
22 size_t size = 0;
23
24 size += lttng_ust_lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
25 size += sizeof(unsigned long);
26 return size;
27 }
28
29 static
30 void pthread_id_record(struct lttng_ust_ctx_field *field,
31 struct lttng_ust_lib_ring_buffer_ctx *ctx,
32 struct lttng_ust_channel_buffer *chan)
33 {
34 unsigned long pthread_id;
35
36 pthread_id = (unsigned long) pthread_self();
37 lttng_ust_lib_ring_buffer_align_ctx(ctx, lttng_alignof(pthread_id));
38 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id));
39 }
40
41 static
42 void pthread_id_get_value(struct lttng_ust_ctx_field *field,
43 struct lttng_ust_ctx_value *value)
44 {
45 value->u.s64 = (unsigned long) pthread_self();
46 }
47
48 int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx)
49 {
50 struct lttng_ust_ctx_field *field;
51 struct lttng_ust_type_common *type;
52 int ret;
53
54 type = lttng_ust_create_type_integer(sizeof(unsigned long) * CHAR_BIT,
55 lttng_alignof(unsigned long) * CHAR_BIT,
56 lttng_ust_is_signed_type(unsigned long),
57 BYTE_ORDER, 10);
58 if (!type)
59 return -ENOMEM;
60 field = lttng_append_context(ctx);
61 if (!field) {
62 ret = -ENOMEM;
63 goto error_context;
64 }
65 if (lttng_find_context(*ctx, "pthread_id")) {
66 ret = -EEXIST;
67 goto error_find_context;
68 }
69 field->event_field->name = strdup("pthread_id");
70 if (!field->event_field->name) {
71 ret = -ENOMEM;
72 goto error_name;
73 }
74 field->event_field->type = type;
75 field->get_size = pthread_id_get_size;
76 field->record = pthread_id_record;
77 field->get_value = pthread_id_get_value;
78 lttng_context_update(*ctx);
79 return 0;
80
81 error_name:
82 error_find_context:
83 lttng_remove_context_field(ctx, field);
84 error_context:
85 lttng_ust_destroy_type(type);
86 return ret;
87 }
This page took 0.033088 seconds and 5 git commands to generate.