move allocation of talloc contexts into link-time constructor
This is much more optimal than checking if the context exists every
time we allocate the respective object.
diff --git a/openbsc/src/mncc.c b/openbsc/src/mncc.c
index b2dab07..8cd62f6 100644
--- a/openbsc/src/mncc.c
+++ b/openbsc/src/mncc.c
@@ -140,9 +140,6 @@
if (call->remote_ref)
return 0;
- if (!tall_call_ctx)
- tall_call_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "gsm_call");
/* create remote call */
if (!(remote = talloc(tall_call_ctx, struct gsm_call))) {
memset(&mncc, 0, sizeof(struct gsm_mncc));
@@ -306,9 +303,6 @@
if (!call) {
if (msg_type != MNCC_SETUP_IND)
return 0; /* drop */
- if (!tall_call_ctx)
- tall_call_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "gsm_call");
/* create call */
if (!(call = talloc_zero(tall_call_ctx, struct gsm_call))) {
struct gsm_mncc rel;
@@ -395,3 +389,8 @@
return rc;
}
+
+static __attribute__((constructor)) void on_dso_load_trau_mncc(void)
+{
+ tall_call_ctx = talloc_named_const(tall_bsc_ctx, 1, "gsm_call");
+}