mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
dtls: Shutdown timeout thread when it's not needed
It is not needed most of the time and usually we have a thread idling around doing nothing all the time after the first few seconds.
This commit is contained in:
parent
0ee027b6ee
commit
4072666c7d
1 changed files with 27 additions and 19 deletions
|
@ -247,8 +247,6 @@ gst_dtls_connection_start (GstDtlsConnection * self, gboolean is_client)
|
||||||
{
|
{
|
||||||
GstDtlsConnectionPrivate *priv;
|
GstDtlsConnectionPrivate *priv;
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
|
|
||||||
|
|
||||||
priv = self->priv;
|
priv = self->priv;
|
||||||
|
|
||||||
g_return_if_fail (priv->send_closure);
|
g_return_if_fail (priv->send_closure);
|
||||||
|
@ -277,14 +275,13 @@ gst_dtls_connection_start (GstDtlsConnection * self, gboolean is_client)
|
||||||
openssl_poll (self);
|
openssl_poll (self);
|
||||||
|
|
||||||
log_state (self, "first poll done");
|
log_state (self, "first poll done");
|
||||||
priv->thread = NULL;
|
|
||||||
|
|
||||||
GST_TRACE_OBJECT (self, "unlocking @ start");
|
GST_TRACE_OBJECT (self, "unlocking @ start");
|
||||||
g_mutex_unlock (&priv->mutex);
|
g_mutex_unlock (&priv->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gst_dtls_connection_start_timeout (GstDtlsConnection * self)
|
gst_dtls_connection_start_timeout_locked (GstDtlsConnection * self)
|
||||||
{
|
{
|
||||||
GstDtlsConnectionPrivate *priv;
|
GstDtlsConnectionPrivate *priv;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -293,13 +290,11 @@ gst_dtls_connection_start_timeout (GstDtlsConnection * self)
|
||||||
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
|
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
|
||||||
|
|
||||||
priv = self->priv;
|
priv = self->priv;
|
||||||
|
if (priv->thread)
|
||||||
|
return;
|
||||||
|
|
||||||
thread_name = g_strdup_printf ("connection_thread_%p", self);
|
thread_name = g_strdup_printf ("connection_thread_%p", self);
|
||||||
|
|
||||||
GST_TRACE_OBJECT (self, "locking @ start_timeout");
|
|
||||||
g_mutex_lock (&priv->mutex);
|
|
||||||
GST_TRACE_OBJECT (self, "locked @ start_timeout");
|
|
||||||
|
|
||||||
GST_INFO_OBJECT (self, "starting connection timeout");
|
GST_INFO_OBJECT (self, "starting connection timeout");
|
||||||
priv->thread = g_thread_try_new (thread_name,
|
priv->thread = g_thread_try_new (thread_name,
|
||||||
(GThreadFunc) connection_timeout_thread_func, self, &error);
|
(GThreadFunc) connection_timeout_thread_func, self, &error);
|
||||||
|
@ -310,9 +305,23 @@ gst_dtls_connection_start_timeout (GstDtlsConnection * self)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (thread_name);
|
g_free (thread_name);
|
||||||
|
}
|
||||||
|
|
||||||
GST_TRACE_OBJECT (self, "unlocking @ start_timeout");
|
void
|
||||||
|
gst_dtls_connection_start_timeout (GstDtlsConnection * self)
|
||||||
|
{
|
||||||
|
GstDtlsConnectionPrivate *priv;
|
||||||
|
|
||||||
|
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
|
||||||
|
|
||||||
|
priv = self->priv;
|
||||||
|
|
||||||
|
GST_TRACE_OBJECT (self, "locking @ start_timeout");
|
||||||
|
g_mutex_lock (&priv->mutex);
|
||||||
|
GST_TRACE_OBJECT (self, "locked @ start_timeout");
|
||||||
|
gst_dtls_connection_start_timeout_locked (self);
|
||||||
g_mutex_unlock (&priv->mutex);
|
g_mutex_unlock (&priv->mutex);
|
||||||
|
GST_TRACE_OBJECT (self, "unlocking @ start_timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -541,15 +550,11 @@ connection_timeout_thread_func (GstDtlsConnection * self)
|
||||||
log_state (self, "handling timeout after poll");
|
log_state (self, "handling timeout after poll");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG_OBJECT (self, "waiting indefinitely");
|
GST_DEBUG_OBJECT (self, "no timeout set, stopping thread");
|
||||||
|
|
||||||
priv->timeout_set = FALSE;
|
priv->timeout_set = FALSE;
|
||||||
|
priv->thread = NULL;
|
||||||
while (!priv->timeout_set && priv->is_alive) {
|
g_mutex_unlock (&priv->mutex);
|
||||||
GST_TRACE_OBJECT (self, "wait @ timeout");
|
break;
|
||||||
g_cond_wait (&priv->condition, &priv->mutex);
|
|
||||||
}
|
|
||||||
GST_TRACE_OBJECT (self, "continued @ timeout");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_TRACE_OBJECT (self, "unlocking @ timeout");
|
GST_TRACE_OBJECT (self, "unlocking @ timeout");
|
||||||
|
@ -854,7 +859,10 @@ bio_method_ctrl (BIO * bio, int cmd, long arg1, void *arg2)
|
||||||
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
|
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
|
||||||
GST_LOG_OBJECT (self, "BIO: Timeout set");
|
GST_LOG_OBJECT (self, "BIO: Timeout set");
|
||||||
priv->timeout_set = TRUE;
|
priv->timeout_set = TRUE;
|
||||||
g_cond_signal (&priv->condition);
|
if (priv->thread)
|
||||||
|
g_cond_signal (&priv->condition);
|
||||||
|
else
|
||||||
|
gst_dtls_connection_start_timeout_locked (self);
|
||||||
return 1;
|
return 1;
|
||||||
case BIO_CTRL_RESET:
|
case BIO_CTRL_RESET:
|
||||||
priv->bio_buffer = NULL;
|
priv->bio_buffer = NULL;
|
||||||
|
|
Loading…
Reference in a new issue