mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1411977 - Part 2: Stop using sync dispatch and queue jumping with SingletonThreadHolder. r=drno
MozReview-Commit-ID: F2BbHI2kiK1 --HG-- extra : rebase_source : 0f6aef6343a71bce29327d79766b8b84a2cfa1d2
This commit is contained in:
parent
aaf0e9394c
commit
e066f9f6f4
@ -208,16 +208,9 @@ public:
|
||||
* Keep track of how many instances are using a SingletonThreadHolder.
|
||||
* When no one is using it, shut it down
|
||||
*/
|
||||
void AddUse()
|
||||
{
|
||||
RUN_ON_THREAD(mParentThread,
|
||||
mozilla::WrapRunnable(RefPtr<SingletonThreadHolder>(this),
|
||||
&SingletonThreadHolder::AddUse_i),
|
||||
NS_DISPATCH_SYNC);
|
||||
}
|
||||
|
||||
void AddUse_i()
|
||||
void AddUse()
|
||||
{
|
||||
MOZ_ASSERT(mParentThread == NS_GetCurrentThread());
|
||||
MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt");
|
||||
nsrefcnt count = ++mUseCount;
|
||||
if (count == 1) {
|
||||
@ -232,14 +225,6 @@ public:
|
||||
}
|
||||
|
||||
void ReleaseUse()
|
||||
{
|
||||
RUN_ON_THREAD(mParentThread,
|
||||
mozilla::WrapRunnable(RefPtr<SingletonThreadHolder>(this),
|
||||
&SingletonThreadHolder::ReleaseUse_i),
|
||||
NS_DISPATCH_SYNC);
|
||||
}
|
||||
|
||||
void ReleaseUse_i()
|
||||
{
|
||||
MOZ_ASSERT(mParentThread == NS_GetCurrentThread());
|
||||
nsrefcnt count = --mUseCount;
|
||||
@ -1144,18 +1129,15 @@ NrUdpSocketIpc::NrUdpSocketIpc()
|
||||
|
||||
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
|
||||
// destroy_i also dispatches back to STS to call ReleaseUse, to avoid shutting
|
||||
// down the IO thread before close() runs.
|
||||
RUN_ON_THREAD(io_thread_,
|
||||
mozilla::WrapRunnableNM(&NrUdpSocketIpc::release_child_i,
|
||||
socket_child_.forget().take()),
|
||||
mozilla::WrapRunnableNM(&NrUdpSocketIpc::destroy_i,
|
||||
socket_child_.forget().take(),
|
||||
sts_thread_),
|
||||
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
|
||||
}
|
||||
|
||||
@ -1347,6 +1329,7 @@ int NrUdpSocketIpc::create(nr_transport_addr *addr) {
|
||||
|
||||
state_ = NR_CONNECTING;
|
||||
|
||||
MOZ_ASSERT(io_thread_);
|
||||
RUN_ON_THREAD(io_thread_,
|
||||
mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
|
||||
&NrUdpSocketIpc::create_i,
|
||||
@ -1638,14 +1621,25 @@ void NrUdpSocketIpc::close_i() {
|
||||
}
|
||||
|
||||
#if defined(MOZILLA_INTERNAL_API)
|
||||
|
||||
static void ReleaseIOThread_s()
|
||||
{
|
||||
sThread->ReleaseUse();
|
||||
}
|
||||
|
||||
// close(), but transfer the socket_child_ reference to die as well
|
||||
// static
|
||||
void NrUdpSocketIpc::release_child_i(nsIUDPSocketChild* aChild) {
|
||||
void NrUdpSocketIpc::destroy_i(nsIUDPSocketChild* aChild,
|
||||
nsCOMPtr<nsIEventTarget>& aStsThread) {
|
||||
RefPtr<nsIUDPSocketChild> socket_child_ref =
|
||||
already_AddRefed<nsIUDPSocketChild>(aChild);
|
||||
if (socket_child_ref) {
|
||||
socket_child_ref->Close();
|
||||
}
|
||||
|
||||
RUN_ON_THREAD(aStsThread,
|
||||
WrapRunnableNM(&ReleaseIOThread_s),
|
||||
NS_DISPATCH_NORMAL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -280,7 +280,8 @@ private:
|
||||
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);
|
||||
static void destroy_i(nsIUDPSocketChild* aChild,
|
||||
nsCOMPtr<nsIEventTarget>& aStsThread);
|
||||
#endif
|
||||
// STS thread executor
|
||||
void recv_callback_s(RefPtr<nr_udp_message> msg);
|
||||
|
Loading…
Reference in New Issue
Block a user