Bug 1332402 - Part 1: Simplify shutdown of the IO thread. r=jesup draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 19 Jan 2017 14:06:21 -0600
changeset 464254 388fac2352fc5a7e83b91e7b011358458171e9a7
parent 463681 a3978751f45108ff1ae002ecebdc0fa23fc52b84
child 464255 87d10a7c546f6f85f8e2c769e20afcc63ea724ef
push id42321
push userbcampen@mozilla.com
push dateFri, 20 Jan 2017 19:39:15 +0000
reviewersjesup
bugs1332402
milestone53.0a1
Bug 1332402 - Part 1: Simplify shutdown of the IO thread. r=jesup MozReview-Commit-ID: DsGcaQGxz7u
media/mtransport/nr_socket_prsock.cpp
media/mtransport/nr_socket_prsock.h
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -1130,19 +1130,21 @@ NrUdpSocketIpc::~NrUdpSocketIpc()
 {
   // also guarantees socket_child_ is released from the io_thread, and
   // tells the SingletonThreadHolder we're done with it
 
 #if defined(MOZILLA_INTERNAL_API)
   // close(), but transfer the socket_child_ reference to die as well
   RUN_ON_THREAD(io_thread_,
                 mozilla::WrapRunnableNM(&NrUdpSocketIpc::release_child_i,
-                                        socket_child_.forget().take(),
-                                        sts_thread_),
+                                        socket_child_.forget().take()),
                 NS_DISPATCH_NORMAL);
+  // This may shut down the io_thread_, but it should spin the event loop so
+  // the above runnable happens.
+  sThread->ReleaseUse();
 #endif
 }
 
 // IUDPSocketInternal interfaces
 // callback while error happened in UDP socket operation
 NS_IMETHODIMP NrUdpSocketIpc::CallListenerError(const nsACString &message,
                                                 const nsACString &filename,
                                                 uint32_t line_number) {
@@ -1616,31 +1618,22 @@ void NrUdpSocketIpc::close_i() {
     socket_child_->Close();
     socket_child_ = nullptr;
   }
 }
 
 #if defined(MOZILLA_INTERNAL_API)
 // close(), but transfer the socket_child_ reference to die as well
 // static
-void NrUdpSocketIpc::release_child_i(nsIUDPSocketChild* aChild,
-                                     nsCOMPtr<nsIEventTarget> sts_thread) {
+void NrUdpSocketIpc::release_child_i(nsIUDPSocketChild* aChild) {
   RefPtr<nsIUDPSocketChild> socket_child_ref =
     already_AddRefed<nsIUDPSocketChild>(aChild);
   if (socket_child_ref) {
     socket_child_ref->Close();
   }
-  // Tell SingletonThreadHolder we're done with it
-  RUN_ON_THREAD(sts_thread,
-                mozilla::WrapRunnableNM(&NrUdpSocketIpc::release_use_s),
-                NS_DISPATCH_NORMAL);
-}
-
-void NrUdpSocketIpc::release_use_s() {
-  sThread->ReleaseUse();
 }
 #endif
 
 void NrUdpSocketIpc::recv_callback_s(RefPtr<nr_udp_message> msg) {
   ASSERT_ON_THREAD(sts_thread_);
 
   {
     ReentrantMonitorAutoEnter mon(monitor_);
--- a/media/mtransport/nr_socket_prsock.h
+++ b/media/mtransport/nr_socket_prsock.h
@@ -276,18 +276,17 @@ private:
   nsresult SetAddress();  // Set the local address from parent info.
 
   // Main or private thread executors of the NrSocketBase APIs
   void create_i(const nsACString &host, const uint16_t port);
   void connect_i(const nsACString &host, const uint16_t port);
   void sendto_i(const net::NetAddr &addr, nsAutoPtr<DataBuffer> buf);
   void close_i();
 #if defined(MOZILLA_INTERNAL_API) && !defined(MOZILLA_XPCOMRT_API)
-  static void release_child_i(nsIUDPSocketChild* aChild, nsCOMPtr<nsIEventTarget> ststhread);
-  static void release_use_s();
+  static void release_child_i(nsIUDPSocketChild* aChild);
 #endif
   // STS thread executor
   void recv_callback_s(RefPtr<nr_udp_message> msg);
 
   ReentrantMonitor monitor_; // protects err_and state_
   bool err_;
   NrSocketIpcState state_;