From 979daea7f2f3cdfad06494360f2084ff106723c1 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 8 Mar 2019 00:37:39 +1100 Subject: [PATCH] tests/webrtc: fix racy test with a prenegotiated data channel If both data channels become ready simultaneously, then the two integer read-add-update cycles can execute concurrently and only ever increment once instead of the required twice. Use an atomic add instead. --- ext/webrtc/webrtcdatachannel.h | 5 +++-- tests/check/elements/webrtcbin.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/webrtc/webrtcdatachannel.h b/ext/webrtc/webrtcdatachannel.h index 769844171c..8523fb5705 100644 --- a/ext/webrtc/webrtcdatachannel.h +++ b/ext/webrtc/webrtcdatachannel.h @@ -75,8 +75,9 @@ struct _GstWebRTCDataChannelClass }; void gst_webrtc_data_channel_start_negotiation (GstWebRTCDataChannel *channel); -void gst_webrtc_data_channel_set_sctp_transport (GstWebRTCDataChannel *channel, - GstWebRTCSCTPTransport *sctp); +G_GNUC_INTERNAL +void gst_webrtc_data_channel_link_to_sctp (GstWebRTCDataChannel *channel, + GstWebRTCSCTPTransport *sctp_transport); G_END_DECLS diff --git a/tests/check/elements/webrtcbin.c b/tests/check/elements/webrtcbin.c index 15636aed80..540be5122f 100644 --- a/tests/check/elements/webrtcbin.c +++ b/tests/check/elements/webrtcbin.c @@ -1899,8 +1899,9 @@ _on_ready_state_notify (GObject * channel, GParamSpec * pspec, g_object_get (channel, "ready-state", &ready_state, NULL); if (ready_state == GST_WEBRTC_DATA_CHANNEL_STATE_OPEN) { - if (++(*n_ready) >= 2) + if (g_atomic_int_add (n_ready, 1) >= 1) { test_webrtc_signal_state (t, STATE_CUSTOM); + } } }