Bug 1332402 - Part 1: Simplify shutdown of the IO thread. r=jesup
MozReview-Commit-ID: DsGcaQGxz7u
--- 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_;