netwerk/ipc/ChannelEventQueue.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial