Update ABI to select the output method
[lttng-modules.git] / ltt-context.c
... / ...
CommitLineData
1/*
2 * ltt-context.c
3 *
4 * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng trace/channel/event context management.
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11#include <linux/module.h>
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/slab.h>
15#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
16#include "ltt-events.h"
17#include "ltt-tracer.h"
18
19struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p)
20{
21 struct lttng_ctx_field *field;
22 struct lttng_ctx *ctx;
23
24 if (!*ctx_p) {
25 *ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL);
26 if (!*ctx_p)
27 return NULL;
28 }
29 ctx = *ctx_p;
30 if (ctx->nr_fields + 1 > ctx->allocated_fields) {
31 struct lttng_ctx_field *new_fields;
32
33 ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields);
34 new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL);
35 if (!new_fields)
36 return NULL;
37 if (ctx->fields)
38 memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields);
39 kfree(ctx->fields);
40 ctx->fields = new_fields;
41 }
42 field = &ctx->fields[ctx->nr_fields];
43 ctx->nr_fields++;
44 return field;
45}
46EXPORT_SYMBOL_GPL(lttng_append_context);
47
48void lttng_remove_context_field(struct lttng_ctx **ctx_p,
49 struct lttng_ctx_field *field)
50{
51 struct lttng_ctx *ctx;
52
53 ctx = *ctx_p;
54 ctx->nr_fields--;
55 memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field));
56}
57EXPORT_SYMBOL_GPL(lttng_remove_context_field);
58
59void lttng_destroy_context(struct lttng_ctx *ctx)
60{
61 int i;
62
63 if (!ctx)
64 return;
65 for (i = 0; i < ctx->nr_fields; i++) {
66 if (ctx->fields[i].destroy)
67 ctx->fields[i].destroy(&ctx->fields[i]);
68 }
69 kfree(ctx->fields);
70 kfree(ctx);
71}
This page took 0.023226 seconds and 4 git commands to generate.