Bug 1413356: dispatch inside SingletonThreadHolder if needed. r?jesup
MozReview-Commit-ID: 8u7v2nKs09P
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -205,20 +205,25 @@ 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,
+ // only dispatch if we are on the wrong thread
+ if (mParentThread == NS_GetCurrentThread()) {
+ AddUse_i();
+ } else {
+ mParentThread->Dispatch(
mozilla::WrapRunnable(RefPtr<SingletonThreadHolder>(this),
&SingletonThreadHolder::AddUse_i),
NS_DISPATCH_SYNC);
+ }
}
void AddUse_i()
{
MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt");
nsrefcnt count = ++mUseCount;
if (count == 1) {
// idle -> in-use
@@ -228,20 +233,25 @@ public:
r_log(LOG_GENERIC,LOG_DEBUG,"Created wrapped SingletonThread %p",
mThread.get());
}
r_log(LOG_GENERIC,LOG_DEBUG,"AddUse_i: %lu", (unsigned long) count);
}
void ReleaseUse()
{
- RUN_ON_THREAD(mParentThread,
- mozilla::WrapRunnable(RefPtr<SingletonThreadHolder>(this),
- &SingletonThreadHolder::ReleaseUse_i),
- NS_DISPATCH_SYNC);
+ // only dispatch if we are on the wrong thread
+ if (mParentThread == NS_GetCurrentThread()) {
+ ReleaseUse_i();
+ } else {
+ mParentThread->Dispatch(
+ mozilla::WrapRunnable(RefPtr<SingletonThreadHolder>(this),
+ &SingletonThreadHolder::ReleaseUse_i),
+ NS_DISPATCH_SYNC);
+ }
}
void ReleaseUse_i()
{
MOZ_ASSERT(mParentThread == NS_GetCurrentThread());
nsrefcnt count = --mUseCount;
MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt");
if (mThread && count == 0) {