blob: f15cd2a2caeb4e527ac9b9a0dcd0a27798f32f85 [file] [log] [blame]
Harald Welte2d906112019-03-18 17:17:43 +01001/*! \file talloc.h */
Harald Welte90e614f2015-12-05 23:38:18 +01002#pragma once
3#include <talloc.h>
Harald Welte2d906112019-03-18 17:17:43 +01004
5/*! per-thread talloc contexts. This works around the problem that talloc is not
6 * thread-safe. However, one can simply have a different set of talloc contexts for each
7 * thread, and ensure that allocations made on one thread are always only free'd on that
8 * very same thread.
9 * WARNING: Users must make sure they free() on the same thread as they allocate!! */
10struct osmo_talloc_contexts {
11 /*! global per-thread talloc context. */
12 void *global;
13 /*! volatile select-dispatch context. This context is completely free'd and
14 * re-created every time the main select loop in osmo_select_main() returns from
15 * select(2) and calls per-fd callback functions. This allows users of this
16 * facility to allocate temporary objects like string buffers, message buffers
17 * and the like which are automatically free'd when going into the next select()
18 * system call */
19 void *select;
20};
21
22extern __thread struct osmo_talloc_contexts *osmo_ctx;
23
24/* short-hand #defines for the osmo talloc contexts (OTC) that can be used to pass
25 * to the various _c functions like msgb_alloc_c() */
26#define OTC_GLOBAL (osmo_ctx->global)
27#define OTC_SELECT (osmo_ctx->select)
Daniel Willmann0a2b2572020-12-28 22:25:45 +010028
29int osmo_ctx_init(const char *id);