summaryrefslogtreecommitdiff
path: root/socket/tcp-bsd.c
diff options
context:
space:
mode:
authorJuan Navarro <juan.navarro@gmx.es>2018-08-20 18:01:02 +0200
committerOlivier CrĂȘte <olivier.crete@collabora.com>2018-10-28 14:47:32 +0000
commitda41258a21102f63ec5d5b2dc20d303f772eb195 (patch)
treead9165967d92e82b57678e1d9d967bfe9767fa98 /socket/tcp-bsd.c
parent78bdcfad5738d21b200ec283918dfd93e17b3d85 (diff)
downloadlibnice-da41258a21102f63ec5d5b2dc20d303f772eb195.tar.gz
Use per-agent locks and GWeakRefs in callbacks from timeout sources
Work on libnice's bug #1 in Gitlab. This work is composed of multiple merged parts: - "Global lock contention removed" Phabricator D1900: https://phabricator.freedesktop.org/D1900 By @nifigase Opened in GitLab as Merge Request !12 - "agent: properly handle NiceAgent ref in callbacks from timeout sources" Phabricator D1898: https://phabricator.freedesktop.org/D1898 By @mparis This patch was itself based upon a previous version of the work done in D1900. After the switch of hosting, it got lost. On top of these, additions to follow some review comments from @ocrete: - https://phabricator.freedesktop.org/D1900#40412 - https://phabricator.freedesktop.org/D1898#39332
Diffstat (limited to 'socket/tcp-bsd.c')
-rw-r--r--socket/tcp-bsd.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c
index 285d323..d5dd633 100644
--- a/socket/tcp-bsd.c
+++ b/socket/tcp-bsd.c
@@ -60,6 +60,7 @@
#define TCP_NODELAY 1
typedef struct {
+ GMutex mutex;
NiceAddress remote_addr;
GQueue send_queue;
GMainContext *context;
@@ -101,6 +102,7 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
if (ctx == NULL)
ctx = g_main_context_default ();
+ g_mutex_init (&priv->mutex);
priv->context = g_main_context_ref (ctx);
priv->remote_addr = *remote_addr;
priv->error = FALSE;
@@ -227,6 +229,8 @@ socket_close (NiceSocket *sock)
if (priv->context)
g_main_context_unref (priv->context);
+ g_mutex_clear (&priv->mutex);
+
g_slice_free(TcpPriv, sock->priv);
}
@@ -424,12 +428,12 @@ socket_send_more (
NiceSocket *sock = (NiceSocket *) data;
TcpPriv *priv = sock->priv;
- agent_lock ();
+ g_mutex_lock (&priv->mutex);
if (g_source_is_destroyed (g_main_current_source ())) {
nice_debug ("Source was destroyed. "
"Avoided race condition in tcp-bsd.c:socket_send_more");
- agent_unlock ();
+ g_mutex_unlock (&priv->mutex);
return FALSE;
}
@@ -441,7 +445,7 @@ socket_send_more (
g_source_unref (priv->io_source);
priv->io_source = NULL;
- agent_unlock ();
+ g_mutex_unlock (&priv->mutex);
if (priv->writable_cb)
priv->writable_cb (sock, priv->writable_data);
@@ -449,6 +453,6 @@ socket_send_more (
return FALSE;
}
- agent_unlock ();
+ g_mutex_unlock (&priv->mutex);
return TRUE;
}