Refactoring: Privatize ring buffer config header
[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-context.h>
15
16 #include "context-internal.h"
17
18 static
19 size_t pthread_id_get_size(struct lttng_ust_ctx_field *field, size_t offset)
20 {
21 size_t size = 0;
22
23 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
24 size += sizeof(unsigned long);
25 return size;
26 }
27
28 static
29 void pthread_id_record(struct lttng_ust_ctx_field *field,
30 struct lttng_ust_lib_ring_buffer_ctx *ctx,
31 struct lttng_channel *chan)
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
40 static
41 void pthread_id_get_value(struct lttng_ust_ctx_field *field,
42 struct lttng_ust_ctx_value *value)
43 {
44 value->u.s64 = (unsigned long) pthread_self();
45 }
46
47 int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx)
48 {
49 struct lttng_ust_ctx_field *field;
50 struct lttng_ust_type_common *type;
51 int ret;
52
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)
58 return -ENOMEM;
59 field = lttng_append_context(ctx);
60 if (!field) {
61 ret = -ENOMEM;
62 goto error_context;
63 }
64 if (lttng_find_context(*ctx, "pthread_id")) {
65 ret = -EEXIST;
66 goto error_find_context;
67 }
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;
74 field->get_size = pthread_id_get_size;
75 field->record = pthread_id_record;
76 field->get_value = pthread_id_get_value;
77 lttng_context_update(*ctx);
78 return 0;
79
80 error_name:
81 error_find_context:
82 lttng_remove_context_field(ctx, field);
83 error_context:
84 lttng_ust_destroy_type(type);
85 return ret;
86 }
This page took 0.031324 seconds and 5 git commands to generate.