netwerk/ipc/ChannelEventQueue.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * vim: set sw=2 ts=8 et tw=80 :
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "nsISupports.h"
     9 #include "mozilla/net/ChannelEventQueue.h"
    10 #include "nsThreadUtils.h"
    12 namespace mozilla {
    13 namespace net {
    15 void
    16 ChannelEventQueue::FlushQueue()
    17 {
    18   // Events flushed could include destruction of channel (and our own
    19   // destructor) unless we make sure its refcount doesn't drop to 0 while this
    20   // method is running.
    21   nsCOMPtr<nsISupports> kungFuDeathGrip(mOwner);
    23   // Prevent flushed events from flushing the queue recursively
    24   mFlushing = true;
    26   uint32_t i;
    27   for (i = 0; i < mEventQueue.Length(); i++) {
    28     mEventQueue[i]->Run();
    29     if (mSuspended)
    30       break;
    31   }
    33   // We will always want to remove at least one finished callback.
    34   if (i < mEventQueue.Length())
    35     i++;
    37   // It is possible for new callbacks to be enqueued as we are
    38   // flushing the queue, so the queue must not be cleared until
    39   // all callbacks have run.
    40   mEventQueue.RemoveElementsAt(0, i);
    42   mFlushing = false;
    43 }
    45 void
    46 ChannelEventQueue::Resume()
    47 {
    48   // Resuming w/o suspend: error in debug mode, ignore in build
    49   MOZ_ASSERT(mSuspendCount > 0);
    50   if (mSuspendCount <= 0) {
    51     return;
    52   }
    54   if (!--mSuspendCount) {
    55     nsRefPtr<nsRunnableMethod<ChannelEventQueue> > event =
    56       NS_NewRunnableMethod(this, &ChannelEventQueue::CompleteResume);
    57     if (mTargetThread) {
    58       mTargetThread->Dispatch(event, NS_DISPATCH_NORMAL);
    59     } else {
    60       MOZ_RELEASE_ASSERT(NS_IsMainThread());
    61       NS_DispatchToCurrentThread(event);
    62     }
    63   }
    64 }
    66 nsresult
    67 ChannelEventQueue::RetargetDeliveryTo(nsIEventTarget* aTargetThread)
    68 {
    69   MOZ_RELEASE_ASSERT(NS_IsMainThread());
    70   MOZ_RELEASE_ASSERT(!mTargetThread);
    71   MOZ_RELEASE_ASSERT(aTargetThread);
    73   mTargetThread = do_QueryInterface(aTargetThread);
    74   MOZ_RELEASE_ASSERT(mTargetThread);
    76   return NS_OK;
    77 }
    79 }
    80 }

mercurial