aboutsummaryrefslogtreecommitdiffstats
path: root/src/libosmo-mgcp/mgcp_protocol.c
diff options
context:
space:
mode:
authorEric <ewild@sysmocom.de>2021-08-13 00:14:18 +0200
committerEric <ewild@sysmocom.de>2021-09-13 18:49:49 +0200
commit55fdfc223ea0584ec88fb392f729e205c021ace2 (patch)
tree78e0c92d15f17b3592179498079c60fdd29aed32 /src/libosmo-mgcp/mgcp_protocol.c
parent8f333036606cae184d8ab2078c49ee248f96cb3d (diff)
globally lock the portrange when trying to grab a port to prep for multithreading
Diffstat (limited to 'src/libosmo-mgcp/mgcp_protocol.c')
-rw-r--r--src/libosmo-mgcp/mgcp_protocol.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index ba80d7d79..16b7dab1a 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -28,6 +28,7 @@
#include <limits.h>
#include <unistd.h>
#include <errno.h>
+#include <pthread.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/talloc.h>
@@ -478,6 +479,7 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)
range = &endp->cfg->net_ports;
+ pthread_mutex_lock(&range->lock);
/* attempt to find a port */
tries = (range->range_end - range->range_start) / 2;
for (i = 0; i < tries; ++i) {
@@ -490,11 +492,12 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)
range->last_port += 2;
if (rc == 0) {
+ pthread_mutex_unlock(&range->lock);
return 0;
}
}
-
+ pthread_mutex_unlock(&range->lock);
LOGPENDP(endp, DLMGCP, LOGL_ERROR,
"Allocating a RTP/RTCP port failed %u times.\n",
tries);
@@ -1606,6 +1609,7 @@ struct mgcp_config *mgcp_config_alloc(void)
osmo_strlcpy(cfg->domain, "mgw", sizeof(cfg->domain));
+ cfg->net_ports.lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
cfg->net_ports.range_start = RTP_PORT_DEFAULT_RANGE_START;
cfg->net_ports.range_end = RTP_PORT_DEFAULT_RANGE_END;
cfg->net_ports.last_port = cfg->net_ports.range_start;