Bug 1600906 - Use move semantics with IdleDatabaseInfo. r=dom-workers-and-storage-reviewers,ytausky
authorSimon Giesecke <sgiesecke@mozilla.com>
Fri, 13 Dec 2019 12:21:18 +0000
changeset 506892 bcee5e565d96199886577ed808d753179801c990
parent 506891 9b4c307ed8a46258a4fb6cc2869a84241f9a75dc
child 506893 cd458b52a7ea62095673888b9155b9045abe2458
push id36913
push useropoprus@mozilla.com
push dateFri, 13 Dec 2019 16:53:24 +0000
treeherdermozilla-central@1ed684598bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-workers-and-storage-reviewers, ytausky
bugs1600906
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1600906 - Use move semantics with IdleDatabaseInfo. r=dom-workers-and-storage-reviewers,ytausky Differential Revision: https://phabricator.services.mozilla.com/D56012
dom/indexedDB/ActorsParent.cpp
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -5224,28 +5224,40 @@ struct ConnectionPool::IdleResource {
 
  protected:
   explicit IdleResource(const TimeStamp& aIdleTime);
 
   ~IdleResource();
 };
 
 struct ConnectionPool::IdleDatabaseInfo final : public IdleResource {
-  DatabaseInfo* mDatabaseInfo;
-
- public:
-  MOZ_IMPLICIT
-  IdleDatabaseInfo(DatabaseInfo* aDatabaseInfo);
-
-  explicit IdleDatabaseInfo(const IdleDatabaseInfo& aOther) = delete;
+  InitializedOnceMustBeTrue<DatabaseInfo* const> mDatabaseInfo;
+
+ public:
+  explicit IdleDatabaseInfo(DatabaseInfo* aDatabaseInfo);
+
+  IdleDatabaseInfo(const IdleDatabaseInfo& aOther) = delete;
+  IdleDatabaseInfo(IdleDatabaseInfo&& aOther) noexcept
+      : IdleResource(std::move(aOther)),
+        mDatabaseInfo{std::move(aOther.mDatabaseInfo)} {
+    MOZ_ASSERT(mDatabaseInfo);
+
+    MOZ_COUNT_CTOR(ConnectionPool::IdleDatabaseInfo);
+  }
+  IdleDatabaseInfo& operator=(const IdleDatabaseInfo& aOther) = delete;
+  IdleDatabaseInfo& operator=(IdleDatabaseInfo&& aOther) = delete;
 
   ~IdleDatabaseInfo();
 
   bool operator==(const IdleDatabaseInfo& aOther) const {
-    return mDatabaseInfo == aOther.mDatabaseInfo;
+    return *mDatabaseInfo == *aOther.mDatabaseInfo;
+  }
+
+  bool operator==(DatabaseInfo* const aDatabaseInfo) const {
+    return *mDatabaseInfo == aDatabaseInfo;
   }
 
   bool operator<(const IdleDatabaseInfo& aOther) const {
     return mIdleTime < aOther.mIdleTime;
   }
 };
 
 struct ConnectionPool::IdleThreadInfo final : public IdleResource {
@@ -11139,20 +11151,20 @@ void ConnectionPool::IdleTimerCallback(n
   TimeStamp now = TimeStamp::NowLoRes() + TimeDuration::FromMilliseconds(500);
 
   uint32_t index = 0;
 
   for (uint32_t count = self->mIdleDatabases.Length(); index < count; index++) {
     IdleDatabaseInfo& info = self->mIdleDatabases[index];
 
     if (now >= info.mIdleTime) {
-      if (info.mDatabaseInfo->mIdle) {
-        self->PerformIdleDatabaseMaintenance(info.mDatabaseInfo);
+      if ((*info.mDatabaseInfo)->mIdle) {
+        self->PerformIdleDatabaseMaintenance(*info.mDatabaseInfo);
       } else {
-        self->CloseDatabase(info.mDatabaseInfo);
+        self->CloseDatabase(*info.mDatabaseInfo);
       }
     } else {
       break;
     }
   }
 
   if (index) {
     self->mIdleDatabases.RemoveElementsAt(0, index);
@@ -11552,17 +11564,17 @@ void ConnectionPool::ShutdownThread(Thre
 void ConnectionPool::CloseIdleDatabases() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mShutdownRequested);
 
   AUTO_PROFILER_LABEL("ConnectionPool::CloseIdleDatabases", DOM);
 
   if (!mIdleDatabases.IsEmpty()) {
     for (IdleDatabaseInfo& idleInfo : mIdleDatabases) {
-      CloseDatabase(idleInfo.mDatabaseInfo);
+      CloseDatabase(*idleInfo.mDatabaseInfo);
     }
     mIdleDatabases.Clear();
   }
 
   if (!mDatabasesPerformingIdleMaintenance.IsEmpty()) {
     for (DatabaseInfo* dbInfo : mDatabasesPerformingIdleMaintenance) {
       MOZ_ASSERT(dbInfo);
       CloseDatabase(dbInfo);
@@ -11843,17 +11855,17 @@ void ConnectionPool::NoteIdleDatabase(Da
       // thread down immediately instead of going through the idle thread
       // mechanism.
       ShutdownThread(aDatabaseInfo->mThreadInfo);
     }
 
     return;
   }
 
-  mIdleDatabases.InsertElementSorted(aDatabaseInfo);
+  mIdleDatabases.InsertElementSorted(IdleDatabaseInfo{aDatabaseInfo});
 
   AdjustIdleTimer();
 }
 
 void ConnectionPool::NoteClosedDatabase(DatabaseInfo* aDatabaseInfo) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aDatabaseInfo);
   MOZ_ASSERT(aDatabaseInfo->mClosing);
@@ -12354,17 +12366,16 @@ ConnectionPool::IdleDatabaseInfo::IdleDa
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aDatabaseInfo);
 
   MOZ_COUNT_CTOR(ConnectionPool::IdleDatabaseInfo);
 }
 
 ConnectionPool::IdleDatabaseInfo::~IdleDatabaseInfo() {
   AssertIsOnBackgroundThread();
-  MOZ_ASSERT(mDatabaseInfo);
 
   MOZ_COUNT_DTOR(ConnectionPool::IdleDatabaseInfo);
 }
 
 ConnectionPool::IdleThreadInfo::IdleThreadInfo(ThreadInfo aThreadInfo)
     : IdleResource(TimeStamp::NowLoRes() +
                    TimeDuration::FromMilliseconds(kConnectionThreadIdleMS)),
       mThreadInfo(std::move(aThreadInfo)) {