mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1556911 - Don't instantiate NetworkConnectivityService off-main-thread r=dragana
This patch calls NetworkConnectivityService::GetSingleton() on the main thread and keeps a ref to the service until shutdown. Even though calling ncs->GetIPv6() off-main-thread is technically a data-race in practice that's OK because only the simple decision whether to send AAAA requests is made based on that value, which in itself is an optimization. I filed bug 1556967 for making the connectivity service thread safe. Differential Revision: https://phabricator.services.mozilla.com/D33765 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0da1d200eb
commit
50fee6b27e
@ -6,6 +6,9 @@
|
||||
#define NetworkConnectivityService_h_
|
||||
|
||||
#include "nsINetworkConnectivityService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIDNSListener.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/StaticPrefs.h"
|
||||
#include "mozilla/net/NetworkConnectivityService.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::net;
|
||||
@ -599,6 +598,7 @@ nsresult nsHostResolver::Init() {
|
||||
LOG(("nsHostResolver::Init this=%p", this));
|
||||
|
||||
mShutdown = false;
|
||||
mNCS = NetworkConnectivityService::GetSingleton();
|
||||
|
||||
// The preferences probably haven't been loaded from the disk yet, so we
|
||||
// need to register a callback that will set up the experiment once they
|
||||
@ -746,6 +746,8 @@ void nsHostResolver::Shutdown() {
|
||||
}
|
||||
// empty host database
|
||||
mRecordDB.Clear();
|
||||
|
||||
mNCS = nullptr;
|
||||
}
|
||||
|
||||
ClearPendingQueue(pendingQHigh);
|
||||
@ -1241,15 +1243,12 @@ nsresult nsHostResolver::TrrLookup(nsHostRecord* aRec, TRR* pushedTRR) {
|
||||
}
|
||||
bool sendAgain;
|
||||
|
||||
RefPtr<NetworkConnectivityService> ncs =
|
||||
NetworkConnectivityService::GetSingleton();
|
||||
|
||||
do {
|
||||
sendAgain = false;
|
||||
if ((TRRTYPE_AAAA == rectype) && gTRRService &&
|
||||
(gTRRService->DisableIPv6() ||
|
||||
(gTRRService->CheckIPv6Connectivity() &&
|
||||
ncs->GetIPv6() == nsINetworkConnectivityService::NOT_AVAILABLE))) {
|
||||
(gTRRService->CheckIPv6Connectivity() && mNCS &&
|
||||
mNCS->GetIPv6() == nsINetworkConnectivityService::NOT_AVAILABLE))) {
|
||||
break;
|
||||
}
|
||||
LOG(("TRR Resolve %s type %d\n", addrRec->host.get(), (int)rectype));
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsIThreadPool.h"
|
||||
#include "mozilla/net/NetworkConnectivityService.h"
|
||||
|
||||
class nsHostResolver;
|
||||
class nsResolveHostCallback;
|
||||
@ -552,6 +553,7 @@ class nsHostResolver : public nsISupports, public AHostResolver {
|
||||
mozilla::TimeDuration mShortIdleTimeout;
|
||||
|
||||
RefPtr<nsIThreadPool> mResolverThreads;
|
||||
RefPtr<mozilla::net::NetworkConnectivityService> mNCS;
|
||||
|
||||
mozilla::Atomic<bool> mShutdown;
|
||||
mozilla::Atomic<uint32_t> mNumIdleTasks;
|
||||
|
Loading…
Reference in New Issue
Block a user