Bug 853998 - Convert sync dispatches from SIPCC threads to use SyncRunnable r=jesup
authorAdam Roach [:abr] <adam@nostrum.com>
Wed, 27 Mar 2013 21:43:44 -0500
changeset 126514 687b479332b3d1fbdf184d7eb855ccc9a8b02275
parent 126513 9a04c4a506dfe80e08f2fc66dfbb26d3b301c253
child 126515 d507ab8a001946dfae3357686f583275733cfb27
push id24485
push userryanvm@gmail.com
push dateThu, 28 Mar 2013 12:31:20 +0000
treeherdermozilla-central@293498096b28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs853998
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 853998 - Convert sync dispatches from SIPCC threads to use SyncRunnable r=jesup
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
media/webrtc/signaling/test/mediapipeline_unittest.cpp
media/webrtc/signaling/test/signaling_unittests.cpp
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
@@ -18,16 +18,17 @@
 #include "nsThreadUtils.h"
 #include "transportflow.h"
 #include "transportlayer.h"
 #include "transportlayerdtls.h"
 #include "transportlayerice.h"
 #include "runnable_utils.h"
 #include "cpr_stdlib.h"
 #include "cpr_string.h"
+#include "mozilla/SyncRunnable.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <ssl.h>
 #include <sslproto.h>
 #include <algorithm>
 
 extern "C" {
@@ -510,30 +511,29 @@ short vcmRxAllocICE(cc_mcapid_t mcap_id,
                    uint16_t level,
                    char **default_addrp, /* Out */
                    int *default_portp, /* Out */
                    char ***candidatesp, /* Out */
                    int *candidate_ctp /* Out */
                    )
 {
   int ret;
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmRxAllocICE_m,
                         mcap_id,
                         group_id,
                         stream_id,
                         call_handle,
                         peerconnection,
                         level,
                         default_addrp,
                         default_portp,
                         candidatesp,
                         candidate_ctp,
-                        &ret),
-          NS_DISPATCH_SYNC);
+                        &ret));
   return ret;
 }
 
 /* Get ICE global parameters (ufrag and pwd)
  *  @param[in]  peerconnection - the peerconnection in use
  *  @param[out] ufragp - where to put the ufrag
  *  @param[out] pwdp - where to put the pwd
  *
@@ -604,23 +604,22 @@ static short vcmGetIceParams_m(const cha
  *
  *  @return 0 for success; VCM_ERROR for failure
  */
 short vcmGetIceParams(const char *peerconnection,
                      char **ufragp,
                      char **pwdp)
 {
   int ret;
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmGetIceParams_m,
                         peerconnection,
                         ufragp,
                         pwdp,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
   return ret;
 }
 
 
 /* Set remote ICE global parameters.
  *
  *  @param[in]  peerconnection - the peerconnection in use
  *  @param[in]  ufrag - the ufrag
@@ -666,23 +665,22 @@ static short vcmSetIceSessionParams_m(co
  *  @return 0 success, error failure
  */
 short vcmSetIceSessionParams(const char *peerconnection,
                              char *ufrag,
                              char *pwd)
 {
   short ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmSetIceSessionParams_m,
                         peerconnection,
                         ufrag,
                         pwd,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 /* Set ice candidate for trickle ICE.
  *
  *  @param[in]  peerconnection - the peerconnection in use
  *  @param[in]  icecandidate - the icecandidate
@@ -733,23 +731,22 @@ static short vcmSetIceCandidate_m(const 
  *  @return 0 success, error failure
  */
 short vcmSetIceCandidate(const char *peerconnection,
                          const char *icecandidate,
                          uint16_t level)
 {
   short ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmSetIceCandidate_m,
                         peerconnection,
                         icecandidate,
                         level,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 
 /* Start ICE checks
  *  @param[in]  peerconnection - the peerconnection in use
  *  @return 0 success, error failure
@@ -789,22 +786,21 @@ static short vcmStartIceChecks_m(const c
  *
  *  @param[in]  peerconnection - the peerconnection in use
  *  @return 0 success, error failure
  */
 short vcmStartIceChecks(const char *peerconnection, cc_boolean isControlling)
 {
   short ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmStartIceChecks_m,
                         peerconnection,
                         isControlling,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 /* Set remote ICE media-level parameters.
  *
  *  @param[in]  peerconnection - the peerconnection in use
  *  @param[in]  level - the m-line
@@ -869,26 +865,25 @@ short vcmSetIceMediaParams(const char *p
                            int level,
                            char *ufrag,
                            char *pwd,
                            char **candidates,
                            int candidate_ct)
 {
   short ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmSetIceMediaParams_m,
                      peerconnection,
                      level,
                      ufrag,
                      pwd,
                      candidates,
                      candidate_ct,
-                     &ret),
-      NS_DISPATCH_SYNC);
+                     &ret));
 
   return ret;
 }
 
 
 /*
  * Create a remote stream
  *
@@ -945,23 +940,22 @@ static short vcmCreateRemoteStream_m(
  *  Returns: zero(0) for success; otherwise, ERROR for failure
  */
 short vcmCreateRemoteStream(cc_mcapid_t mcap_id,
                             const char *peerconnection,
                             int *pc_stream_id)
 {
   short ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmCreateRemoteStream_m,
                         mcap_id,
                         peerconnection,
                         pc_stream_id,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 
 /*
  * Get DTLS key data
  *
@@ -1031,25 +1025,24 @@ static short vcmGetDtlsIdentity_m(const 
  */
 short vcmGetDtlsIdentity(const char *peerconnection,
                          char *digest_algp,
                          size_t max_digest_alg_len,
                          char *digestp,
                          size_t max_digest_len) {
   short ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmGetDtlsIdentity_m,
                         peerconnection,
                         digest_algp,
                         max_digest_alg_len,
                         digestp,
                         max_digest_len,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 /* Set negotiated DataChannel parameters.
  *
  *  @param[in]  peerconnection - the peerconnection in use
  *  @param[in]  streams - the number of streams for this data channel
@@ -1444,33 +1437,32 @@ int vcmRxStartICE(cc_mcapid_t mcap_id,
                   int num_payloads,
                   const vcm_payload_info_t* payloads,
                   const char *fingerprint_alg,
                   const char *fingerprint,
                   vcm_mediaAttrs_t *attrs)
 {
   int ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmRxStartICE_m,
                         mcap_id,
                         group_id,
                         stream_id,
                         level,
                         pc_stream_id,
                         pc_track_id,
                         call_handle,
                         peerconnection,
                         num_payloads,
                         payloads,
                         fingerprint_alg,
                         fingerprint,
                         attrs,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 
 /**
  *  Close the receive stream.
  *
@@ -2078,33 +2070,32 @@ int vcmTxStartICE(cc_mcapid_t mcap_id,
                   const vcm_payload_info_t *payload,
                   short tos,
                   const char *fingerprint_alg,
                   const char *fingerprint,
                   vcm_mediaAttrs_t *attrs)
 {
   int ret;
 
-  VcmSIPCCBinding::getMainThread()->Dispatch(
+  mozilla::SyncRunnable::DispatchToThread(VcmSIPCCBinding::getMainThread(),
       WrapRunnableNMRet(&vcmTxStartICE_m,
                         mcap_id,
                         group_id,
                         stream_id,
                         level,
                         pc_stream_id,
                         pc_track_id,
                         call_handle,
                         peerconnection,
                         payload,
                         tos,
                         fingerprint_alg,
                         fingerprint,
                         attrs,
-                        &ret),
-      NS_DISPATCH_SYNC);
+                        &ret));
 
   return ret;
 }
 
 
 /**
  *  Close the transmit stream
  *
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -19,16 +19,17 @@
 #include "runnable_utils.h"
 #include "cpr_socket.h"
 #include "debug-psipcc-types.h"
 
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "mozilla/Services.h"
 #include "StaticPtr.h"
+#include "mozilla/SyncRunnable.h"
 
 static const char* logTag = "PeerConnectionCtx";
 
 extern "C" {
 extern PRCondVar *ccAppReadyToStartCond;
 extern PRLock *ccAppReadyToStartLock;
 extern char ccAppReadyToStart;
 }
@@ -256,27 +257,24 @@ void PeerConnectionCtx::onDeviceEvent(cc
                   device_event_getname(aDeviceEvent));
   }
 }
 
 void PeerConnectionCtx::onCallEvent(ccapi_call_event_e aCallEvent,
                                       CSF::CC_CallPtr aCall,
                                       CSF::CC_CallInfoPtr aInfo) {
   // This is called on a SIPCC thread.
-  // WARNING: Do not make this NS_DISPATCH_NORMAL.
   // CC_*Ptr is not thread-safe so we must not manipulate
   // the ref count on multiple threads at once.
-  // NS_DISPATCH_SYNC enforces this and because this is
-  // not a real nsThread, we don't have to worry about
-  // reentrancy.
-  RUN_ON_THREAD(gMainThread,
+  // SyncRunnable enforces this and because it doesn't process
+  // incoming events, we don't have to worry about reentrancy.
+  mozilla::SyncRunnable::DispatchToThread(gMainThread,
                 WrapRunnable(this,
                              &PeerConnectionCtx::onCallEvent_m,
-                             aCallEvent, aCall, aInfo),
-                NS_DISPATCH_SYNC);
+                             aCallEvent, aCall, aInfo));
 }
 
 // Demux the call event to the right PeerConnection
 void PeerConnectionCtx::onCallEvent_m(ccapi_call_event_e aCallEvent,
                                       CSF::CC_CallPtr aCall,
                                       CSF::CC_CallInfoPtr aInfo) {
   CSFLogDebug(logTag, "onCallEvent()");
   PeerConnectionWrapper pc(aCall->getPeerConnection());
--- a/media/webrtc/signaling/test/mediapipeline_unittest.cpp
+++ b/media/webrtc/signaling/test/mediapipeline_unittest.cpp
@@ -21,16 +21,17 @@
 #include "FakeMediaStreamsImpl.h"
 #include "MediaConduitErrors.h"
 #include "MediaConduitInterface.h"
 #include "MediaPipeline.h"
 #include "runnable_utils.h"
 #include "transportflow.h"
 #include "transportlayerprsock.h"
 #include "transportlayerdtls.h"
+#include "mozilla/SyncRunnable.h"
 
 
 #include "mtransport_test_utils.h"
 #include "runnable_utils.h"
 
 #define GTEST_HAS_RTTI 0
 #include "gtest/gtest.h"
 #include "gtest_utils.h"
@@ -59,19 +60,20 @@ class TestAgent {
       video_pipeline_() {
   }
 
   void ConnectSocket(PRFileDesc *fd, bool client) {
     nsresult res;
     res = audio_prsock_->Init();
     ASSERT_EQ((nsresult)NS_OK, res);
 
-    test_utils->sts_target()->Dispatch(
-        WrapRunnable(audio_prsock_, &TransportLayerPrsock::Import,
-                     fd, &res), NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnable(audio_prsock_, &TransportLayerPrsock::Import, fd, &res));
+
     ASSERT_TRUE(NS_SUCCEEDED(res));
 
     ASSERT_EQ((nsresult)NS_OK, audio_flow_->PushLayer(audio_prsock_));
 
     std::vector<uint16_t> ciphers;
     ciphers.push_back(SRTP_AES128_CM_HMAC_SHA1_80);
     audio_dtls_->SetSrtpCiphers(ciphers);
     audio_dtls_->SetIdentity(DtlsIdentity::Generate());
@@ -82,39 +84,39 @@ class TestAgent {
 
   virtual void CreatePipelines_s() = 0;
 
   void Start() {
     nsresult ret;
 
     MOZ_MTLOG(PR_LOG_DEBUG, "Starting");
 
-    test_utils->sts_target()->Dispatch(
-        WrapRunnableRet(audio_->GetStream(),
-                        &Fake_MediaStream::Start, &ret),
-        NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnableRet(audio_->GetStream(), &Fake_MediaStream::Start, &ret));
+
     ASSERT_TRUE(NS_SUCCEEDED(ret));
   }
 
   void StopInt() {
     audio_->GetStream()->Stop();
     audio_flow_ = NULL;
     video_flow_ = NULL;
     if (audio_pipeline_)
       audio_pipeline_->ShutdownTransport_s();
     if (video_pipeline_)
       video_pipeline_->ShutdownTransport_s();
   }
 
   void Stop() {
     MOZ_MTLOG(PR_LOG_DEBUG, "Stopping");
 
-    test_utils->sts_target()->Dispatch(
-        WrapRunnable(this, &TestAgent::StopInt),
-        NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnable(this, &TestAgent::StopInt));
 
     if (audio_pipeline_)
       audio_pipeline_->ShutdownMedia_m();
     if (video_pipeline_)
       video_pipeline_->ShutdownMedia_m();
     audio_pipeline_ = NULL;
     video_pipeline_ = NULL;
 
@@ -207,29 +209,31 @@ class MediaPipelineTest : public ::testi
   MediaPipelineTest() : p1_() {
     fds_[0] = fds_[1] = NULL;
   }
 
   void SetUp() {
     PRStatus status = PR_NewTCPSocketPair(fds_);
     ASSERT_EQ(status, PR_SUCCESS);
 
-    test_utils->sts_target()->Dispatch(
-      WrapRunnable(&p1_, &TestAgent::ConnectSocket, fds_[0], false),
-      NS_DISPATCH_SYNC);
-    test_utils->sts_target()->Dispatch(
-      WrapRunnable(&p2_, &TestAgent::ConnectSocket, fds_[1], false),
-      NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnable(&p1_, &TestAgent::ConnectSocket, fds_[0], false));
+
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnable(&p2_, &TestAgent::ConnectSocket, fds_[1], false));
 
-    test_utils->sts_target()->Dispatch(
-      WrapRunnable(&p1_, &TestAgent::CreatePipelines_s),
-      NS_DISPATCH_SYNC);
-    test_utils->sts_target()->Dispatch(
-      WrapRunnable(&p2_, &TestAgent::CreatePipelines_s),
-      NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnable(&p1_, &TestAgent::CreatePipelines_s));
+
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnable(&p2_, &TestAgent::CreatePipelines_s));
   }
 
  protected:
   PRFileDesc *fds_[2];
   TestAgentSend p1_;
   TestAgentReceive p2_;
 };
 
--- a/media/webrtc/signaling/test/signaling_unittests.cpp
+++ b/media/webrtc/signaling/test/signaling_unittests.cpp
@@ -28,16 +28,17 @@ using namespace std;
 #include "nsStaticComponents.h"
 #include "nsIDOMRTCPeerConnection.h"
 #include "nsServiceManagerUtils.h"
 #include "nsNetUtil.h"
 #include "nsIIOService.h"
 #include "nsIDNSService.h"
 #include "nsWeakReference.h"
 #include "nricectx.h"
+#include "mozilla/SyncRunnable.h"
 
 #include "mtransport_test_utils.h"
 MtransportTestUtils *test_utils;
 nsCOMPtr<nsIThread> gThread;
 
 
 static int kDefaultTimeout = 5000;
 
@@ -520,19 +521,18 @@ class ParsedSDP {
   int num_lines;
 };
 
 class SignalingAgent {
  public:
   SignalingAgent() : pc(nullptr) {}
 
   ~SignalingAgent() {
-    pc->GetMainThread()->Dispatch(
-      WrapRunnable(this, &SignalingAgent::Close),
-      NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(pc->GetMainThread(),
+      WrapRunnable(this, &SignalingAgent::Close));
   }
 
   void Init_m(nsCOMPtr<nsIThread> thread)
   {
     pc = sipcc::PeerConnectionImpl::CreatePeerConnection();
     ASSERT_TRUE(pc);
 
     pObserver = new TestObserver(pc);
@@ -541,31 +541,29 @@ class SignalingAgent {
     sipcc::IceConfiguration cfg;
     cfg.addServer("23.21.150.121", 3478);
     ASSERT_EQ(pc->Initialize(pObserver, nullptr, cfg, thread), NS_OK);
 
   }
 
   void Init(nsCOMPtr<nsIThread> thread)
   {
-    thread->Dispatch(
-      WrapRunnable(this, &SignalingAgent::Init_m, thread),
-      NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(thread,
+      WrapRunnable(this, &SignalingAgent::Init_m, thread));
 
     ASSERT_TRUE_WAIT(sipcc_state() == sipcc::PeerConnectionImpl::kStarted,
                      kDefaultTimeout);
     ASSERT_TRUE_WAIT(ice_state() == sipcc::PeerConnectionImpl::kIceWaiting, 5000);
     cout << "Init Complete" << endl;
   }
 
   bool InitAllowFail(nsCOMPtr<nsIThread> thread)
   {
-    thread->Dispatch(
-        WrapRunnable(this, &SignalingAgent::Init_m, thread),
-        NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(thread,
+        WrapRunnable(this, &SignalingAgent::Init_m, thread));
 
     EXPECT_TRUE_WAIT(sipcc_state() == sipcc::PeerConnectionImpl::kStarted,
                      kDefaultTimeout);
     EXPECT_TRUE_WAIT(ice_state() == sipcc::PeerConnectionImpl::kIceWaiting ||
                      ice_state() == sipcc::PeerConnectionImpl::kIceFailed, 5000);
 
     if (ice_state() == sipcc::PeerConnectionImpl::kIceFailed) {
       cout << "Init Failed" << endl;
@@ -628,19 +626,19 @@ class SignalingAgent {
   void CreateOffer(sipcc::MediaConstraints& constraints,
                    uint32_t offerFlags, uint32_t sdpCheck) {
 
     // Create a media stream as if it came from GUM
     Fake_AudioStreamSource *audio_stream =
       new Fake_AudioStreamSource();
 
     nsresult ret;
-    test_utils->sts_target()->Dispatch(
-      WrapRunnableRet(audio_stream, &Fake_MediaStream::Start, &ret),
-        NS_DISPATCH_SYNC);
+    mozilla::SyncRunnable::DispatchToThread(
+      test_utils->sts_target(),
+      WrapRunnableRet(audio_stream, &Fake_MediaStream::Start, &ret));
 
     ASSERT_TRUE(NS_SUCCEEDED(ret));
 
     // store in object to be used by RemoveStream
     nsRefPtr<DOMMediaStream> domMediaStream = new DOMMediaStream(audio_stream);
     domMediaStream_ = domMediaStream;
 
     uint32_t aHintContents = 0;