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/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");
+}