summaryrefslogtreecommitdiff
path: root/ext/dtls/gstdtlsconnection.c
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2015-03-18 18:17:39 +0100
committerSebastian Dröge <sebastian@centricular.com>2015-03-18 18:21:35 +0100
commit4072666c7dac6647588a29c0b0316e1682fe7b08 (patch)
tree21217d4bda090c2d894656b875016faf3be70d90 /ext/dtls/gstdtlsconnection.c
parent0ee027b6ee61bf75051ea8cc34e9b9dd171dc5f9 (diff)
downloadgstreamer-plugins-bad-4072666c7dac6647588a29c0b0316e1682fe7b08.tar.gz
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.
Diffstat (limited to 'ext/dtls/gstdtlsconnection.c')
-rw-r--r--ext/dtls/gstdtlsconnection.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/ext/dtls/gstdtlsconnection.c b/ext/dtls/gstdtlsconnection.c
index 68e4cd47f..bdd9a1719 100644
--- a/ext/dtls/gstdtlsconnection.c
+++ b/ext/dtls/gstdtlsconnection.c
@@ -247,8 +247,6 @@ gst_dtls_connection_start (GstDtlsConnection * self, gboolean is_client)
{
GstDtlsConnectionPrivate *priv;
- g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
-
priv = self->priv;
g_return_if_fail (priv->send_closure);
@@ -277,14 +275,13 @@ gst_dtls_connection_start (GstDtlsConnection * self, gboolean is_client)
openssl_poll (self);
log_state (self, "first poll done");
- priv->thread = NULL;
GST_TRACE_OBJECT (self, "unlocking @ start");
g_mutex_unlock (&priv->mutex);
}
-void
-gst_dtls_connection_start_timeout (GstDtlsConnection * self)
+static void
+gst_dtls_connection_start_timeout_locked (GstDtlsConnection * self)
{
GstDtlsConnectionPrivate *priv;
GError *error = NULL;
@@ -293,13 +290,11 @@ gst_dtls_connection_start_timeout (GstDtlsConnection * self)
g_return_if_fail (GST_IS_DTLS_CONNECTION (self));
priv = self->priv;
+ if (priv->thread)
+ return;
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");
priv->thread = g_thread_try_new (thread_name,
(GThreadFunc) connection_timeout_thread_func, self, &error);
@@ -310,9 +305,23 @@ gst_dtls_connection_start_timeout (GstDtlsConnection * self)
}
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);
+ GST_TRACE_OBJECT (self, "unlocking @ start_timeout");
}
void
@@ -541,15 +550,11 @@ connection_timeout_thread_func (GstDtlsConnection * self)
log_state (self, "handling timeout after poll");
}
} else {
- GST_DEBUG_OBJECT (self, "waiting indefinitely");
-
+ GST_DEBUG_OBJECT (self, "no timeout set, stopping thread");
priv->timeout_set = FALSE;
-
- while (!priv->timeout_set && priv->is_alive) {
- GST_TRACE_OBJECT (self, "wait @ timeout");
- g_cond_wait (&priv->condition, &priv->mutex);
- }
- GST_TRACE_OBJECT (self, "continued @ timeout");
+ priv->thread = NULL;
+ g_mutex_unlock (&priv->mutex);
+ break;
}
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:
GST_LOG_OBJECT (self, "BIO: Timeout set");
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;
case BIO_CTRL_RESET:
priv->bio_buffer = NULL;