Bug 1253094, part 3 - Stop using DebugOnly for class/struct members in ipc/. r=billm draft
authorJonathan Watt <jwatt@jwatt.org>
Wed, 02 Mar 2016 23:51:59 +0000
changeset 336254 bfbe7da37231e83b3d2bdf52b721281759c48db1
parent 336253 8dba83cfdcf95572c104297624fa42966d47c15c
child 336255 201a36a1b6a02962d50444475580176d62ca1373
push id12025
push userjwatt@jwatt.org
push dateThu, 03 Mar 2016 00:03:10 +0000
reviewersbillm
bugs1253094
milestone47.0a1
Bug 1253094, part 3 - Stop using DebugOnly for class/struct members in ipc/. r=billm MozReview-Commit-ID: BDwErf8QXtC
ipc/glue/BackgroundImpl.cpp
ipc/glue/FileDescriptor.cpp
ipc/glue/FileDescriptor.h
ipc/glue/MessagePump.cpp
--- a/ipc/glue/BackgroundImpl.cpp
+++ b/ipc/glue/BackgroundImpl.cpp
@@ -313,42 +313,50 @@ class ChildImpl final : public Backgroun
 
   // This is only modified on the main thread. It is the thread-local index that
   // we use to store the BackgroundChild for each thread.
   static unsigned int sThreadLocalIndex;
 
   struct ThreadLocalInfo
   {
     explicit ThreadLocalInfo(nsIIPCBackgroundChildCreateCallback* aCallback)
+#ifdef DEBUG
       : mClosed(false)
+#endif
     {
       mCallbacks.AppendElement(aCallback);
     }
 
     RefPtr<ChildImpl> mActor;
     nsTArray<nsCOMPtr<nsIIPCBackgroundChildCreateCallback>> mCallbacks;
     nsAutoPtr<BackgroundChildImpl::ThreadLocal> mConsumerThreadLocal;
-    DebugOnly<bool> mClosed;
+#ifdef DEBUG
+    bool mClosed;
+#endif
   };
 
   // This is only modified on the main thread. It is a FIFO queue for actors
   // that are in the process of construction.
   static StaticAutoPtr<nsTArray<nsCOMPtr<nsIEventTarget>>> sPendingTargets;
 
   // This is only modified on the main thread. It prevents us from trying to
   // create the background thread after application shutdown has started.
   static bool sShutdownHasStarted;
 
 #ifdef RELEASE_BUILD
-  DebugOnly<nsIThread*> mBoundThread;
+#ifdef DEBUG
+  nsIThread* mBoundThread;
+#endif
 #else
   nsIThread* mBoundThread;
 #endif
 
-  DebugOnly<bool> mActorDestroyed;
+#ifdef DEBUG
+  bool mActorDestroyed;
+#endif
 
 public:
   static bool
   OpenProtocolOnMainThread(nsIEventTarget* aEventTarget);
 
   static void
   Shutdown();
 
@@ -370,17 +378,19 @@ public:
   void
   AssertActorDestroyed()
   {
     MOZ_ASSERT(mActorDestroyed, "ChildImpl::ActorDestroy not called in time");
   }
 
   ChildImpl()
   : mBoundThread(nullptr)
+#ifdef DEBUG
   , mActorDestroyed(false)
+#endif
   {
     AssertIsOnMainThread();
   }
 
   NS_INLINE_DECL_REFCOUNTING(ChildImpl)
 
 private:
   // Forwarded from BackgroundChild.
@@ -1607,25 +1617,27 @@ ChildImpl::Shutdown()
   if (sShutdownHasStarted) {
     MOZ_ASSERT_IF(sThreadLocalIndex != kBadThreadLocalIndex,
                   !PR_GetThreadPrivate(sThreadLocalIndex));
     return;
   }
 
   sShutdownHasStarted = true;
 
+#ifdef DEBUG
   MOZ_ASSERT(sThreadLocalIndex != kBadThreadLocalIndex);
 
   auto threadLocalInfo =
     static_cast<ThreadLocalInfo*>(PR_GetThreadPrivate(sThreadLocalIndex));
 
   if (threadLocalInfo) {
     MOZ_ASSERT(!threadLocalInfo->mClosed);
     threadLocalInfo->mClosed = true;
   }
+#endif
 
   DebugOnly<PRStatus> status = PR_SetThreadPrivate(sThreadLocalIndex, nullptr);
   MOZ_ASSERT(status == PR_SUCCESS);
 }
 
 // static
 PBackgroundChild*
 ChildImpl::Alloc(Transport* aTransport, ProcessId aOtherPid)
@@ -1742,18 +1754,20 @@ ChildImpl::CloseForCurrentThread()
              "BackgroundChild::Startup() was never called!");
   auto threadLocalInfo =
     static_cast<ThreadLocalInfo*>(PR_GetThreadPrivate(sThreadLocalIndex));
 
   if (!threadLocalInfo) {
     return;
   }
 
+#ifdef DEBUG
   MOZ_ASSERT(!threadLocalInfo->mClosed);
   threadLocalInfo->mClosed = true;
+#endif
 
   if (threadLocalInfo->mActor) {
     threadLocalInfo->mActor->FlushPendingInterruptQueue();
   }
 
   // Clearing the thread local will synchronously close the actor.
   DebugOnly<PRStatus> status = PR_SetThreadPrivate(sThreadLocalIndex, nullptr);
   MOZ_ASSERT(status == PR_SUCCESS);
@@ -2087,18 +2101,20 @@ ChildImpl::DispatchFailureCallback(nsIEv
   }
 }
 
 void
 ChildImpl::ActorDestroy(ActorDestroyReason aWhy)
 {
   AssertIsOnBoundThread();
 
+#ifdef DEBUG
   MOZ_ASSERT(!mActorDestroyed);
   mActorDestroyed = true;
+#endif
 
   BackgroundChildImpl::ActorDestroy(aWhy);
 }
 
 NS_IMPL_ISUPPORTS(ChildImpl::ShutdownObserver, nsIObserver)
 
 NS_IMETHODIMP
 ChildImpl::ShutdownObserver::Observe(nsISupports* aSubject,
--- a/ipc/glue/FileDescriptor.cpp
+++ b/ipc/glue/FileDescriptor.cpp
@@ -24,23 +24,27 @@
 #include "base/eintr_wrapper.h"
 #define INVALID_HANDLE -1
 
 #endif // XP_WIN
 
 using mozilla::ipc::FileDescriptor;
 
 FileDescriptor::FileDescriptor()
-: mHandle(INVALID_HANDLE), mHandleCreatedByOtherProcess(false),
-  mHandleCreatedByOtherProcessWasUsed(false)
+  : mHandle(INVALID_HANDLE), mHandleCreatedByOtherProcess(false)
+#ifdef DEBUG
+  , mHandleCreatedByOtherProcessWasUsed(false)
+#endif
 { }
 
 FileDescriptor::FileDescriptor(PlatformHandleType aHandle)
-: mHandle(INVALID_HANDLE), mHandleCreatedByOtherProcess(false),
-  mHandleCreatedByOtherProcessWasUsed(false)
+  : mHandle(INVALID_HANDLE), mHandleCreatedByOtherProcess(false)
+#ifdef DEBUG
+  , mHandleCreatedByOtherProcessWasUsed(false)
+#endif
 {
   DuplicateInCurrentProcess(aHandle);
 }
 
 void
 FileDescriptor::DuplicateInCurrentProcess(PlatformHandleType aHandle)
 {
   MOZ_ASSERT_IF(mHandleCreatedByOtherProcess && IsValid(),
--- a/ipc/glue/FileDescriptor.h
+++ b/ipc/glue/FileDescriptor.h
@@ -47,34 +47,38 @@ public:
 
   // This should only ever be created by IPDL.
   struct IPDLPrivate
   {};
 
   FileDescriptor();
 
   FileDescriptor(const FileDescriptor& aOther)
-    : mHandleCreatedByOtherProcess(false),
-      mHandleCreatedByOtherProcessWasUsed(false)
+    : mHandleCreatedByOtherProcess(false)
+#ifdef DEBUG
+    , mHandleCreatedByOtherProcessWasUsed(false)
+#endif
   {
     // Don't use operator= here because that will call
     // CloseCurrentProcessHandle() on this (uninitialized) object.
     Assign(aOther);
   }
 
   explicit FileDescriptor(PlatformHandleType aHandle);
 
   FileDescriptor(const IPDLPrivate&, const PickleType& aPickle)
 #ifdef XP_WIN
   : mHandle(aPickle)
 #else
   : mHandle(aPickle.fd)
 #endif
   , mHandleCreatedByOtherProcess(true)
+#ifdef DEBUG
   , mHandleCreatedByOtherProcessWasUsed(false)
+#endif
   { }
 
   ~FileDescriptor()
   {
     CloseCurrentProcessHandle();
   }
 
   FileDescriptor&
@@ -97,41 +101,47 @@ public:
   IsValid() const
   {
     return IsValid(mHandle);
   }
 
   PlatformHandleType
   PlatformHandle() const
   {
+#ifdef DEBUG
     if (mHandleCreatedByOtherProcess) {
       mHandleCreatedByOtherProcessWasUsed = true;
     }
+#endif
     return mHandle;
   }
 
   bool
   operator==(const FileDescriptor& aOther) const
   {
     return mHandle == aOther.mHandle;
   }
 
 private:
   void
   Assign(const FileDescriptor& aOther)
   {
     if (aOther.mHandleCreatedByOtherProcess) {
       mHandleCreatedByOtherProcess = true;
+#ifdef DEBUG
       mHandleCreatedByOtherProcessWasUsed =
         aOther.mHandleCreatedByOtherProcessWasUsed;
+#endif
       mHandle = aOther.PlatformHandle();
     } else {
       DuplicateInCurrentProcess(aOther.PlatformHandle());
       mHandleCreatedByOtherProcess = false;
+#ifdef DEBUG
       mHandleCreatedByOtherProcessWasUsed = false;
+#endif
     }
   }
 
   static bool
   IsValid(PlatformHandleType aHandle);
 
   void
   DuplicateInCurrentProcess(PlatformHandleType aHandle);
@@ -142,17 +152,19 @@ private:
   PlatformHandleType mHandle;
 
   // If this is true then this instance is created by IPDL to ferry a handle to
   // its eventual consumer and we never close the handle. If this is false then
   // we are a RAII wrapper around the handle and we close the handle on
   // destruction.
   bool mHandleCreatedByOtherProcess;
 
+#ifdef DEBUG
   // This is to ensure that we don't leak the handle (which is only possible
   // when we're in the receiving process).
-  mutable DebugOnly<bool> mHandleCreatedByOtherProcessWasUsed;
+  mutable bool mHandleCreatedByOtherProcessWasUsed;
+#endif
 };
 
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_FileDescriptor_h
--- a/ipc/glue/MessagePump.cpp
+++ b/ipc/glue/MessagePump.cpp
@@ -27,17 +27,19 @@
 #include "ipc/Nuwa.h"
 #endif
 
 using base::TimeTicks;
 using namespace mozilla::ipc;
 
 NS_DEFINE_NAMED_CID(NS_TIMER_CID);
 
-static mozilla::DebugOnly<MessagePump::Delegate*> gFirstDelegate;
+#ifdef DEBUG
+static MessagePump::Delegate* gFirstDelegate;
+#endif
 
 namespace mozilla {
 namespace ipc {
 
 class DoWorkRunnable final : public nsICancelableRunnable,
                              public nsITimerCallback
 {
 public:
@@ -248,25 +250,29 @@ DoWorkRunnable::Cancel()
   return NS_OK;
 }
 
 void
 MessagePumpForChildProcess::Run(base::MessagePump::Delegate* aDelegate)
 {
   if (mFirstRun) {
     MOZ_ASSERT(aDelegate && !gFirstDelegate);
+#ifdef DEBUG
     gFirstDelegate = aDelegate;
+#endif
 
     mFirstRun = false;
     if (NS_FAILED(XRE_RunAppShell())) {
         NS_WARNING("Failed to run app shell?!");
     }
 
     MOZ_ASSERT(aDelegate && aDelegate == gFirstDelegate);
+#ifdef DEBUG
     gFirstDelegate = nullptr;
+#endif
 
     return;
   }
 
   MOZ_ASSERT(aDelegate && aDelegate == gFirstDelegate);
 
   // We can get to this point in startup with Tasks in our loop's
   // incoming_queue_ or pending_queue_, but without a matching