summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/msgb.h
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-09-16 00:15:56 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-09-27 11:46:38 +0200
commitf45334be29016a36594aacc07c90e262e4994525 (patch)
tree14fe8909b0123dd211e30654dffc77fe05b01615 /include/osmocom/core/msgb.h
parent8319a6799ffc9d4c5e7e094b96af30cbebf89f65 (diff)
msgb: add msgb_talloc_ctx_init(), deprecate msgb_set_talloc_ctx()
So far each and every main() scope creates a msgb talloc context and either passes it to msgb_set_talloc_ctx() or sets tall_msgb_ctx directly (by defining it extern first). Remove some code duplication: add one central function that creates the "msgb" talloc context for all. Most users of msgb employ a talloc_named_const(), but osmo-bts uses a talloc_pool() instead. Offer both ways by means of the pool_size argument, and for both ways make sure the context is called "msgb". Suggest that msgb users should move to this new function: deprecate msgb_set_talloc_ctx(). To be able to do so, include core/defs.h in msgb.h. There's a tradeoff between hiding the msgb talloc context behind API that tries to guess all use cases versus avoiding code dup. This patch opts against code dup and boldly assumes that all future use is covered. Also, the new function suggests to not access tall_msgb_ctx directly, which can be considered a style improvement. It seems that not all main scopes that use msgb actually initialize the msgb ctx. As a fallback for these, explicitly initialize tall_msgb_ctx to NULL. Change-Id: I747fbbf977c4d2c868c8dead64cfc5fd86eb8d4c
Diffstat (limited to 'include/osmocom/core/msgb.h')
-rw-r--r--include/osmocom/core/msgb.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index 6f617e28..7c857710 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -23,6 +23,7 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/bits.h>
+#include <osmocom/core/defs.h>
/*! \defgroup msgb Message buffers
* @{
@@ -457,6 +458,8 @@ static inline int msgb_test_invariant(const struct msgb *msg)
/* non inline functions to ease binding */
uint8_t *msgb_data(const struct msgb *msg);
-void msgb_set_talloc_ctx(void *ctx);
+
+void *msgb_talloc_ctx_init(void *root_ctx, unsigned int pool_size);
+void msgb_set_talloc_ctx(void *ctx) OSMO_DEPRECATED("Use msgb_talloc_ctx_init() instead");
/*! @} */