aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2019-12-01 15:37:47 +0100
committerHarald Welte <laforge@osmocom.org>2019-12-01 15:39:12 +0100
commit6a25a61142da9f8b75dc1c1431e7455cb45cd390 (patch)
treed33ff984ec4c5de0f16004a93fae8649573780da
parent1dbbed169a8e7eb0c2f0bc9d97df226345a9e7c4 (diff)
Move fsm_mgcp_client regstration to __attribute__((contructor))
This way we can avoid the runtime overhead of checking whether or not it is initialized over and over again. It also brings this code more in line with other users of osmo_fsm_register(). Change-Id: Ia73ba8e46c13d925e88203e08a8966839e573183
-rw-r--r--src/libosmo-mgcp-client/mgcp_client_fsm.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/libosmo-mgcp-client/mgcp_client_fsm.c b/src/libosmo-mgcp-client/mgcp_client_fsm.c
index e91058609..e38a4ba9a 100644
--- a/src/libosmo-mgcp-client/mgcp_client_fsm.c
+++ b/src/libosmo-mgcp-client/mgcp_client_fsm.c
@@ -606,7 +606,6 @@ struct osmo_fsm_inst *mgcp_conn_create(struct mgcp_client *mgcp, struct osmo_fsm
uint32_t parent_term_evt, uint32_t parent_evt, struct mgcp_conn_peer *conn_peer)
{
struct mgcp_ctx *mgcp_ctx;
- static bool fsm_registered = false;
struct osmo_fsm_inst *fi;
struct in_addr ip_test;
@@ -618,13 +617,6 @@ struct osmo_fsm_inst *mgcp_conn_create(struct mgcp_client *mgcp, struct osmo_fsm
if (conn_peer->port && inet_aton(conn_peer->addr, &ip_test) == 0)
return NULL;
- /* Register the fsm description (if not already done) */
- if (fsm_registered == false) {
- if (osmo_fsm_register(&fsm_mgcp_client) < 0)
- return NULL;
- fsm_registered = true;
- }
-
/* Allocate and configure a new fsm instance */
fi = osmo_fsm_inst_alloc_child(&fsm_mgcp_client, parent_fi, parent_term_evt);
OSMO_ASSERT(fi);
@@ -749,3 +741,8 @@ const char *osmo_mgcpc_conn_peer_name(const struct mgcp_conn_peer *info)
return "empty";
return buf;
}
+
+static __attribute__((constructor)) void osmo_mgcp_client_fsm_init()
+{
+ OSMO_ASSERT(osmo_fsm_register(&fsm_mgcp_client) == 0);
+}