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/abis_nm.c b/openbsc/src/abis_nm.c
index 2b56479..dec4b29 100644
--- a/openbsc/src/abis_nm.c
+++ b/openbsc/src/abis_nm.c
@@ -2056,10 +2056,6 @@
FILE *swl;
int rc = 0;
- if (!tall_fle_ctx)
- tall_fle_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "bs11_file_list_entry");
-
swl = fopen(bs11_sw->swl_fname, "r");
if (!swl)
return -ENODEV;
@@ -2373,3 +2369,10 @@
{
return __simple_cmd(bts, NM_MT_IPACC_RESTART);
}
+
+
+static __attribute__((constructor)) void on_dso_load_abis_nm(void)
+{
+ tall_fle_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "bs11_file_list_entry");
+}
diff --git a/openbsc/src/e1_input.c b/openbsc/src/e1_input.c
index 2d0c134..7531755 100644
--- a/openbsc/src/e1_input.c
+++ b/openbsc/src/e1_input.c
@@ -370,10 +370,6 @@
if (ts->type != E1INP_TS_TYPE_SIGN)
return NULL;
- if (!tall_sigl_ctx)
- tall_sigl_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "e1inp_sign_link");
-
link = talloc_zero(tall_sigl_ctx, struct e1inp_sign_link);
if (!link)
return NULL;
@@ -505,3 +501,9 @@
return 0;
}
+
+static __attribute__((constructor)) void on_dso_load_e1_inp(void)
+{
+ tall_sigl_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "e1inp_sign_link");
+}
diff --git a/openbsc/src/gsm_04_08.c b/openbsc/src/gsm_04_08.c
index 642d059..a9f2ebd 100644
--- a/openbsc/src/gsm_04_08.c
+++ b/openbsc/src/gsm_04_08.c
@@ -350,9 +350,6 @@
use_lchan(lchan);
release_loc_updating_req(lchan);
- if (!tall_locop_ctx)
- tall_locop_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "loc_updating_oper");
lchan->loc_operation = talloc_zero(tall_locop_ctx,
struct gsm_loc_updating_operation);
}
@@ -408,6 +405,8 @@
*/
static __attribute__((constructor)) void on_dso_load_0408(void)
{
+ tall_locop_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "loc_updating_oper");
register_signal_handler(SS_LCHAN, gsm0408_handle_lchan_signal, NULL);
}
diff --git a/openbsc/src/gsm_04_11.c b/openbsc/src/gsm_04_11.c
index 8db402b..9218783 100644
--- a/openbsc/src/gsm_04_11.c
+++ b/openbsc/src/gsm_04_11.c
@@ -162,19 +162,11 @@
u_int8_t address_lv[12]; /* according to 03.40 / 9.1.2.5 */
int rc = 0;
- if (!tall_sms_ctx)
- tall_sms_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "sms_submit");
-
sms = talloc(tall_sms_ctx, struct sms_submit);
if (!sms)
return -ENOMEM;
memset(sms, 0, sizeof(*sms));
- if (!tall_gsms_ctx)
- tall_gsms_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "sms");
-
gsms = talloc(tall_gsms_ctx, struct gsm_sms);
if (!gsms) {
talloc_free(sms);
@@ -513,3 +505,9 @@
return gsm0411_sendmsg(msg);
}
+
+static __attribute__((constructor)) void on_dso_load_sms(void)
+{
+ tall_sms_ctx = talloc_named_const(tall_bsc_ctx, 1, "sms_submit");
+ tall_gsms_ctx = talloc_named_const(tall_bsc_ctx, 1, "sms");
+}
diff --git a/openbsc/src/gsm_subscriber.c b/openbsc/src/gsm_subscriber.c
index e892906..7480156 100644
--- a/openbsc/src/gsm_subscriber.c
+++ b/openbsc/src/gsm_subscriber.c
@@ -103,10 +103,6 @@
{
struct gsm_subscriber *s;
- if (!tall_subscr_ctx)
- tall_subscr_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "subscriber");
-
s = talloc(tall_subscr_ctx, struct gsm_subscriber);
if (!s)
return NULL;
@@ -213,10 +209,6 @@
{
struct subscr_request *request;
- if (!tall_sub_req_ctx)
- tall_sub_req_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "subscr_request");
-
request = talloc(tall_sub_req_ctx, struct subscr_request);
if (!request) {
if (cbfn)
@@ -273,3 +265,11 @@
subscr_send_paging_request(lchan->subscr);
}
+
+static __attribute__((constructor)) void on_dso_load_subscr(void)
+{
+ tall_subscr_ctx = talloc_named_const(tall_bsc_ctx, 1, "subscriber");
+
+ tall_sub_req_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "subscr_request");
+}
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");
+}
diff --git a/openbsc/src/msgb.c b/openbsc/src/msgb.c
index ae13346..52edf2d 100644
--- a/openbsc/src/msgb.c
+++ b/openbsc/src/msgb.c
@@ -33,9 +33,6 @@
{
struct msgb *msg;
- if (!tall_msgb_ctx)
- tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 1, "msgb");
-
msg = _talloc_zero(tall_msgb_ctx, sizeof(*msg) + size, name);
if (!msg)
@@ -76,3 +73,8 @@
return llist_entry(lh, struct msgb, list);
}
+
+static __attribute__((constructor)) void on_dso_load_trau_msgb(void)
+{
+ tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 1, "msgb");
+}
diff --git a/openbsc/src/paging.c b/openbsc/src/paging.c
index 0703e93..b63a717 100644
--- a/openbsc/src/paging.c
+++ b/openbsc/src/paging.c
@@ -219,9 +219,6 @@
struct gsm_bts_paging_state *bts_entry = &bts->paging;
struct gsm_paging_request *req;
- if (!tall_paging_ctx)
- tall_paging_ctx = talloc_named_const(NULL, 1, "paging_request");
-
if (paging_pending_request(bts_entry, subscr)) {
DEBUGP(DPAG, "Paging request already pending\n");
return;
@@ -310,3 +307,8 @@
{
bts->paging.available_slots = free_slots;
}
+
+static __attribute__((constructor)) void on_dso_load_paging(void)
+{
+ tall_paging_ctx = talloc_named_const(NULL, 1, "paging_request");
+}
diff --git a/openbsc/src/signal.c b/openbsc/src/signal.c
index 41352fb..bf5671e 100644
--- a/openbsc/src/signal.c
+++ b/openbsc/src/signal.c
@@ -39,9 +39,6 @@
{
struct signal_handler *sig_data;
- if (!tall_sigh_ctx)
- tall_sigh_ctx = talloc_named_const(NULL, 1, "signal_handler");
-
sig_data = talloc(tall_sigh_ctx, struct signal_handler);
if (!sig_data)
return -ENOMEM;
@@ -84,3 +81,8 @@
(*handler->cbfn)(subsys, signal, handler->data, signal_data);
}
}
+
+static __attribute__((constructor)) void on_dso_load_signal(void)
+{
+ tall_sigh_ctx = talloc_named_const(NULL, 1, "signal_handler");
+}
diff --git a/openbsc/src/subchan_demux.c b/openbsc/src/subchan_demux.c
index ccd4fad..368b985 100644
--- a/openbsc/src/subchan_demux.c
+++ b/openbsc/src/subchan_demux.c
@@ -312,9 +312,6 @@
{
int i;
- if (!tall_tqe_ctx)
- tall_tqe_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "subch_txq_entry");
memset(mx, 0, sizeof(*mx));
for (i = 0; i < NR_SUBCH; i++) {
struct mux_subch *sch = &mx->subch[i];
@@ -323,3 +320,9 @@
return 0;
}
+
+static __attribute__((constructor)) void on_dso_load_ss_demux(void)
+{
+ tall_tqe_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "subch_txq_entry");
+}
diff --git a/openbsc/src/trau_mux.c b/openbsc/src/trau_mux.c
index 04febbd..9ff7001 100644
--- a/openbsc/src/trau_mux.c
+++ b/openbsc/src/trau_mux.c
@@ -55,10 +55,6 @@
{
struct map_entry *me;
- if (!tall_map_ctx)
- tall_map_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "trau_map_entry");
-
me = talloc(tall_map_ctx, struct map_entry);
if (!me)
return -ENOMEM;
@@ -201,10 +197,6 @@
struct gsm_e1_subslot *src_ss;
struct upqueue_entry *ue;
- if (!tall_upq_ctx)
- tall_upq_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "trau_upq_entry");
-
ue = talloc(tall_upq_ctx, struct upqueue_entry);
if (!ue)
return -ENOMEM;
@@ -243,3 +235,12 @@
return subchan_mux_enqueue(mx, dst_e1_ss->e1_ts_ss, trau_bits_out,
TRAU_FRAME_BITS);
}
+
+static __attribute__((constructor)) void on_dso_load_trau_mux(void)
+{
+ tall_map_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "trau_map_entry");
+
+ tall_upq_ctx = talloc_named_const(tall_bsc_ctx, 1,
+ "trau_upq_entry");
+}