2009-06-29 11:38:29 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: sw=4 ts=4 et :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-29 11:38:29 -07:00
|
|
|
|
|
|
|
#ifndef ipc_glue_RPCChannel_h
|
|
|
|
#define ipc_glue_RPCChannel_h 1
|
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-09-11 00:28:09 -07:00
|
|
|
// FIXME/cjones probably shouldn't depend on STL
|
|
|
|
#include <queue>
|
2009-06-29 11:38:29 -07:00
|
|
|
#include <stack>
|
2010-03-18 15:52:32 -07:00
|
|
|
#include <vector>
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2010-03-11 14:24:15 -08:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2011-03-28 12:58:49 -07:00
|
|
|
#include "nsAtomicRefcnt.h"
|
2010-03-11 14:24:15 -08:00
|
|
|
|
2009-07-13 14:55:04 -07:00
|
|
|
#include "mozilla/ipc/SyncChannel.h"
|
2010-02-14 23:47:00 -08:00
|
|
|
#include "nsAutoPtr.h"
|
2009-06-29 11:38:29 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2009-07-13 14:55:04 -07:00
|
|
|
class RPCChannel : public SyncChannel
|
2009-06-29 11:38:29 -07:00
|
|
|
{
|
2010-02-16 10:44:21 -08:00
|
|
|
friend class CxxStackFrame;
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
public:
|
2010-03-10 23:35:30 -08:00
|
|
|
// What happens if RPC calls race?
|
|
|
|
enum RacyRPCPolicy {
|
|
|
|
RRPError,
|
|
|
|
RRPChildWins,
|
|
|
|
RRPParentWins
|
|
|
|
};
|
|
|
|
|
2009-07-15 15:33:37 -07:00
|
|
|
class /*NS_INTERFACE_CLASS*/ RPCListener :
|
|
|
|
public SyncChannel::SyncListener
|
2009-06-29 11:38:29 -07:00
|
|
|
{
|
|
|
|
public:
|
2009-07-15 15:06:30 -07:00
|
|
|
virtual ~RPCListener() { }
|
2009-12-03 00:16:28 -08:00
|
|
|
|
|
|
|
virtual void OnChannelClose() = 0;
|
|
|
|
virtual void OnChannelError() = 0;
|
2009-07-13 14:55:04 -07:00
|
|
|
virtual Result OnMessageReceived(const Message& aMessage) = 0;
|
2010-08-20 16:24:40 -07:00
|
|
|
virtual void OnProcessingError(Result aError) = 0;
|
2010-02-09 16:02:55 -08:00
|
|
|
virtual bool OnReplyTimeout() = 0;
|
2009-07-13 14:55:04 -07:00
|
|
|
virtual Result OnMessageReceived(const Message& aMessage,
|
|
|
|
Message*& aReply) = 0;
|
2009-06-29 11:38:29 -07:00
|
|
|
virtual Result OnCallReceived(const Message& aMessage,
|
2009-07-01 22:45:19 -07:00
|
|
|
Message*& aReply) = 0;
|
2010-10-08 16:24:36 -07:00
|
|
|
virtual void OnChannelConnected(int32 peer_pid) {};
|
2010-02-16 10:44:22 -08:00
|
|
|
|
|
|
|
virtual void OnEnteredCxxStack()
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("default impl shouldn't be invoked");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnExitedCxxStack()
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("default impl shouldn't be invoked");
|
2010-03-10 23:35:30 -08:00
|
|
|
}
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2010-04-29 09:49:00 -07:00
|
|
|
virtual void OnEnteredCall()
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("default impl shouldn't be invoked");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnExitedCall()
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("default impl shouldn't be invoked");
|
|
|
|
}
|
|
|
|
|
2010-03-10 23:35:30 -08:00
|
|
|
virtual RacyRPCPolicy MediateRPCRace(const Message& parent,
|
|
|
|
const Message& child)
|
|
|
|
{
|
|
|
|
return RRPChildWins;
|
|
|
|
}
|
2011-05-18 04:57:08 -07:00
|
|
|
virtual void ProcessRemoteNativeEventsInRPCCall() {};
|
2009-10-08 14:44:43 -07:00
|
|
|
};
|
|
|
|
|
2010-03-10 23:35:30 -08:00
|
|
|
RPCChannel(RPCListener* aListener);
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2009-11-12 14:16:54 -08:00
|
|
|
virtual ~RPCChannel();
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2010-02-14 23:47:00 -08:00
|
|
|
NS_OVERRIDE
|
|
|
|
void Clear();
|
|
|
|
|
2009-07-13 14:55:04 -07:00
|
|
|
// Make an RPC to the other side of the channel
|
|
|
|
bool Call(Message* msg, Message* reply);
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2010-02-16 10:44:21 -08:00
|
|
|
// RPCChannel overrides these so that the async and sync messages
|
|
|
|
// can be counted against mStackFrames
|
|
|
|
NS_OVERRIDE
|
|
|
|
virtual bool Send(Message* msg);
|
|
|
|
NS_OVERRIDE
|
|
|
|
virtual bool Send(Message* msg, Message* reply);
|
|
|
|
|
2010-01-26 22:41:32 -08:00
|
|
|
// Asynchronously, send the child a message that puts it in such a
|
|
|
|
// state that it can't send messages to the parent unless the
|
|
|
|
// parent sends a message to it first. The child stays in this
|
|
|
|
// state until the parent calls |UnblockChild()|.
|
|
|
|
//
|
|
|
|
// It is an error to
|
|
|
|
// - call this on the child side of the channel.
|
|
|
|
// - nest |BlockChild()| calls
|
|
|
|
// - call this when the child is already blocked on a sync or RPC
|
|
|
|
// in-/out- message/call
|
|
|
|
//
|
|
|
|
// Return true iff successful.
|
|
|
|
bool BlockChild();
|
|
|
|
|
|
|
|
// Asynchronously undo |BlockChild()|.
|
|
|
|
//
|
|
|
|
// It is an error to
|
|
|
|
// - call this on the child side of the channel
|
|
|
|
// - call this without a matching |BlockChild()|
|
|
|
|
//
|
|
|
|
// Return true iff successful.
|
|
|
|
bool UnblockChild();
|
|
|
|
|
2010-03-07 12:16:02 -08:00
|
|
|
// Return true iff this has code on the C++ stack.
|
|
|
|
bool IsOnCxxStack() const {
|
2010-03-18 15:52:32 -07:00
|
|
|
return !mCxxStackFrames.empty();
|
2010-03-07 12:16:02 -08:00
|
|
|
}
|
|
|
|
|
2010-01-26 22:41:32 -08:00
|
|
|
NS_OVERRIDE
|
|
|
|
virtual bool OnSpecialMessage(uint16 id, const Message& msg);
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2010-05-21 08:48:34 -07:00
|
|
|
/**
|
|
|
|
* If there is a pending RPC message, process all pending messages.
|
|
|
|
*
|
|
|
|
* @note This method is used on Windows when we detect that an outbound
|
|
|
|
* OLE RPC call is being made to unblock the parent.
|
|
|
|
*/
|
|
|
|
void FlushPendingRPCQueue();
|
|
|
|
|
2010-02-09 14:34:38 -08:00
|
|
|
#ifdef OS_WIN
|
2010-04-28 08:01:09 -07:00
|
|
|
void ProcessNativeEventsInRPCCall();
|
2011-05-18 04:57:08 -07:00
|
|
|
static void NotifyGeckoEventDispatch();
|
2010-04-28 08:01:09 -07:00
|
|
|
|
2010-02-09 14:34:38 -08:00
|
|
|
protected:
|
2010-02-11 22:31:08 -08:00
|
|
|
bool WaitForNotify();
|
2010-03-25 14:53:10 -07:00
|
|
|
void SpinInternalEventLoop();
|
2010-02-09 14:34:38 -08:00
|
|
|
#endif
|
|
|
|
|
2011-11-30 08:24:46 -08:00
|
|
|
protected:
|
|
|
|
NS_OVERRIDE virtual void OnMessageReceivedFromLink(const Message& msg);
|
|
|
|
NS_OVERRIDE virtual void OnChannelErrorFromLink();
|
|
|
|
|
|
|
|
private:
|
2009-10-08 23:21:39 -07:00
|
|
|
// Called on worker thread only
|
2009-09-11 00:28:09 -07:00
|
|
|
|
2010-03-10 23:35:30 -08:00
|
|
|
RPCListener* Listener() const {
|
|
|
|
return static_cast<RPCListener*>(mListener);
|
|
|
|
}
|
|
|
|
|
2010-03-11 21:21:58 -08:00
|
|
|
NS_OVERRIDE
|
2010-04-26 22:42:59 -07:00
|
|
|
virtual bool ShouldDeferNotifyMaybeError() const {
|
2010-03-18 15:52:32 -07:00
|
|
|
return IsOnCxxStack();
|
2010-03-11 21:21:58 -08:00
|
|
|
}
|
|
|
|
|
2010-04-26 22:42:59 -07:00
|
|
|
bool EventOccurred() const;
|
2010-02-09 16:02:54 -08:00
|
|
|
|
2011-01-11 23:07:17 -08:00
|
|
|
void MaybeUndeferIncall();
|
2009-10-08 23:21:39 -07:00
|
|
|
void EnqueuePendingMessages();
|
2009-09-22 08:23:29 -07:00
|
|
|
|
2010-05-21 08:48:34 -07:00
|
|
|
/**
|
|
|
|
* Process one deferred or pending message.
|
|
|
|
* @return true if a message was processed
|
|
|
|
*/
|
|
|
|
bool OnMaybeDequeueOne();
|
|
|
|
|
2011-05-04 13:55:54 -07:00
|
|
|
/**
|
|
|
|
* The "remote view of stack depth" can be different than the
|
|
|
|
* actual stack depth when there are out-of-turn replies. When we
|
|
|
|
* receive one, our actual RPC stack depth doesn't decrease, but
|
|
|
|
* the other side (that sent the reply) thinks it has. So, the
|
|
|
|
* "view" returned here is |stackDepth| minus the number of
|
|
|
|
* out-of-turn replies.
|
|
|
|
*
|
|
|
|
* Only called from the worker thread.
|
|
|
|
*/
|
|
|
|
size_t RemoteViewOfStackDepth(size_t stackDepth) const;
|
|
|
|
|
2009-10-08 23:21:39 -07:00
|
|
|
void Incall(const Message& call, size_t stackDepth);
|
|
|
|
void DispatchIncall(const Message& call);
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2010-01-26 22:41:32 -08:00
|
|
|
void BlockOnParent();
|
|
|
|
void UnblockFromParent();
|
|
|
|
|
2010-02-16 10:44:21 -08:00
|
|
|
// This helper class managed RPCChannel.mCxxStackDepth on behalf
|
|
|
|
// of RPCChannel. When the stack depth is incremented from zero
|
|
|
|
// to non-zero, it invokes an RPCChannel callback, and similarly
|
|
|
|
// for when the depth goes from non-zero to zero;
|
|
|
|
void EnteredCxxStack()
|
|
|
|
{
|
2010-03-10 23:35:30 -08:00
|
|
|
Listener()->OnEnteredCxxStack();
|
2010-02-16 10:44:21 -08:00
|
|
|
}
|
|
|
|
|
2010-03-18 15:52:33 -07:00
|
|
|
void ExitedCxxStack();
|
2010-02-16 10:44:21 -08:00
|
|
|
|
2010-04-29 09:49:00 -07:00
|
|
|
void EnteredCall()
|
|
|
|
{
|
|
|
|
Listener()->OnEnteredCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExitedCall()
|
|
|
|
{
|
|
|
|
Listener()->OnExitedCall();
|
|
|
|
}
|
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
enum Direction { IN_MESSAGE, OUT_MESSAGE };
|
|
|
|
struct RPCFrame {
|
|
|
|
RPCFrame(Direction direction, const Message* msg) :
|
|
|
|
mDirection(direction), mMsg(msg)
|
|
|
|
{ }
|
|
|
|
|
2010-04-29 09:49:00 -07:00
|
|
|
bool IsRPCIncall() const
|
|
|
|
{
|
|
|
|
return mMsg->is_rpc() && IN_MESSAGE == mDirection;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsRPCOutcall() const
|
|
|
|
{
|
|
|
|
return mMsg->is_rpc() && OUT_MESSAGE == mDirection;
|
|
|
|
}
|
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
void Describe(int32* id, const char** dir, const char** sems,
|
2010-04-26 22:42:59 -07:00
|
|
|
const char** name) const
|
2010-03-18 15:52:32 -07:00
|
|
|
{
|
|
|
|
*id = mMsg->routing_id();
|
|
|
|
*dir = (IN_MESSAGE == mDirection) ? "in" : "out";
|
|
|
|
*sems = mMsg->is_rpc() ? "rpc" : mMsg->is_sync() ? "sync" : "async";
|
|
|
|
*name = mMsg->name();
|
|
|
|
}
|
|
|
|
|
|
|
|
Direction mDirection;
|
|
|
|
const Message* mMsg;
|
|
|
|
};
|
|
|
|
|
2010-02-16 10:44:21 -08:00
|
|
|
class NS_STACK_CLASS CxxStackFrame
|
|
|
|
{
|
|
|
|
public:
|
2010-03-18 15:52:32 -07:00
|
|
|
|
|
|
|
CxxStackFrame(RPCChannel& that, Direction direction,
|
|
|
|
const Message* msg) : mThat(that) {
|
2010-02-16 10:44:21 -08:00
|
|
|
mThat.AssertWorkerThread();
|
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
if (mThat.mCxxStackFrames.empty())
|
2010-02-16 10:44:21 -08:00
|
|
|
mThat.EnteredCxxStack();
|
2010-03-23 22:52:47 -07:00
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
mThat.mCxxStackFrames.push_back(RPCFrame(direction, msg));
|
2010-04-29 09:49:00 -07:00
|
|
|
const RPCFrame& frame = mThat.mCxxStackFrames.back();
|
|
|
|
|
|
|
|
if (frame.IsRPCIncall())
|
|
|
|
mThat.EnteredCall();
|
|
|
|
|
|
|
|
mThat.mSawRPCOutMsg |= frame.IsRPCOutcall();
|
2010-02-16 10:44:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CxxStackFrame() {
|
2010-04-29 09:49:00 -07:00
|
|
|
bool exitingCall = mThat.mCxxStackFrames.back().IsRPCIncall();
|
2010-03-18 15:52:32 -07:00
|
|
|
mThat.mCxxStackFrames.pop_back();
|
|
|
|
bool exitingStack = mThat.mCxxStackFrames.empty();
|
2010-02-16 10:44:21 -08:00
|
|
|
|
|
|
|
// mListener could have gone away if Close() was called while
|
|
|
|
// RPCChannel code was still on the stack
|
|
|
|
if (!mThat.mListener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mThat.AssertWorkerThread();
|
2010-04-29 09:49:00 -07:00
|
|
|
if (exitingCall)
|
|
|
|
mThat.ExitedCall();
|
|
|
|
|
2010-02-16 10:44:21 -08:00
|
|
|
if (exitingStack)
|
|
|
|
mThat.ExitedCxxStack();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
RPCChannel& mThat;
|
|
|
|
|
|
|
|
// disable harmful methods
|
|
|
|
CxxStackFrame();
|
|
|
|
CxxStackFrame(const CxxStackFrame&);
|
|
|
|
CxxStackFrame& operator=(const CxxStackFrame&);
|
|
|
|
};
|
|
|
|
|
2009-09-11 00:28:09 -07:00
|
|
|
// Called from both threads
|
2010-04-26 22:42:59 -07:00
|
|
|
size_t StackDepth() const {
|
2011-11-30 08:24:46 -08:00
|
|
|
mMonitor->AssertCurrentThreadOwns();
|
2009-09-11 00:28:09 -07:00
|
|
|
return mStack.size();
|
2009-08-18 22:22:01 -07:00
|
|
|
}
|
|
|
|
|
2009-10-08 15:41:18 -07:00
|
|
|
void DebugAbort(const char* file, int line, const char* cond,
|
2009-10-08 14:44:43 -07:00
|
|
|
const char* why,
|
2010-04-26 22:42:59 -07:00
|
|
|
const char* type="rpc", bool reply=false) const;
|
2009-10-08 14:44:43 -07:00
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
// This method is only safe to call on the worker thread, or in a
|
|
|
|
// debugger with all threads paused. |outfile| defaults to stdout.
|
2010-04-26 22:42:59 -07:00
|
|
|
void DumpRPCStack(FILE* outfile=NULL, const char* const pfx="") const;
|
2010-03-18 15:52:32 -07:00
|
|
|
|
2009-09-11 00:28:09 -07:00
|
|
|
//
|
2009-10-08 23:21:39 -07:00
|
|
|
// Queue of all incoming messages, except for replies to sync
|
|
|
|
// messages, which are delivered directly to the SyncChannel
|
|
|
|
// through its mRecvd member.
|
2009-08-18 22:22:01 -07:00
|
|
|
//
|
2009-09-11 00:28:09 -07:00
|
|
|
// If both this side and the other side are functioning correctly,
|
2009-10-08 23:21:39 -07:00
|
|
|
// the queue can only be in certain configurations. Let
|
2009-09-11 00:28:09 -07:00
|
|
|
//
|
|
|
|
// |A<| be an async in-message,
|
|
|
|
// |S<| be a sync in-message,
|
|
|
|
// |C<| be an RPC in-call,
|
|
|
|
// |R<| be an RPC reply.
|
|
|
|
//
|
2009-10-08 23:21:39 -07:00
|
|
|
// The queue can only match this configuration
|
2009-09-11 00:28:09 -07:00
|
|
|
//
|
|
|
|
// A<* (S< | C< | R< (?{mStack.size() == 1} A<* (S< | C<)))
|
2009-10-08 23:21:39 -07:00
|
|
|
//
|
|
|
|
// The other side can send as many async messages |A<*| as it
|
|
|
|
// wants before sending us a blocking message.
|
|
|
|
//
|
|
|
|
// The first case is |S<|, a sync in-msg. The other side must be
|
|
|
|
// blocked, and thus can't send us any more messages until we
|
|
|
|
// process the sync in-msg.
|
|
|
|
//
|
|
|
|
// The second case is |C<|, an RPC in-call; the other side must be
|
|
|
|
// blocked. (There's a subtlety here: this in-call might have
|
|
|
|
// raced with an out-call, but we detect that with the mechanism
|
2009-09-11 00:28:09 -07:00
|
|
|
// below, |mRemoteStackDepth|, and races don't matter to the
|
|
|
|
// queue.)
|
2009-10-08 23:21:39 -07:00
|
|
|
//
|
2009-09-11 00:28:09 -07:00
|
|
|
// Final case, the other side replied to our most recent out-call
|
2009-10-08 23:21:39 -07:00
|
|
|
// |R<|. If that was the *only* out-call on our stack,
|
|
|
|
// |?{mStack.size() == 1}|, then other side "finished with us,"
|
|
|
|
// and went back to its own business. That business might have
|
2009-09-11 00:28:09 -07:00
|
|
|
// included sending any number of async message |A<*| until
|
2009-10-08 23:21:39 -07:00
|
|
|
// sending a blocking message |(S< | C<)|. If we had more than
|
|
|
|
// one RPC call on our stack, the other side *better* not have
|
|
|
|
// sent us another blocking message, because it's blocked on a
|
|
|
|
// reply from us.
|
2010-04-26 22:42:59 -07:00
|
|
|
//
|
|
|
|
typedef std::queue<Message> MessageQueue;
|
|
|
|
MessageQueue mPending;
|
2009-08-18 22:22:01 -07:00
|
|
|
|
2009-10-08 23:21:39 -07:00
|
|
|
//
|
|
|
|
// Stack of all the RPC out-calls on which this RPCChannel is
|
|
|
|
// awaiting a response.
|
|
|
|
//
|
|
|
|
std::stack<Message> mStack;
|
|
|
|
|
2010-01-21 18:04:10 -08:00
|
|
|
//
|
2010-02-09 14:34:38 -08:00
|
|
|
// Map of replies received "out of turn", because of RPC
|
2010-01-21 18:04:10 -08:00
|
|
|
// in-calls racing with replies to outstanding in-calls. See
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=521929.
|
|
|
|
//
|
2010-02-09 14:34:38 -08:00
|
|
|
typedef std::map<size_t, Message> MessageMap;
|
|
|
|
MessageMap mOutOfTurnReplies;
|
2010-01-21 18:04:10 -08:00
|
|
|
|
2009-10-08 23:21:39 -07:00
|
|
|
//
|
|
|
|
// Stack of RPC in-calls that were deferred because of race
|
|
|
|
// conditions.
|
|
|
|
//
|
|
|
|
std::stack<Message> mDeferred;
|
|
|
|
|
2009-08-18 22:22:01 -07:00
|
|
|
//
|
|
|
|
// This is what we think the RPC stack depth is on the "other
|
|
|
|
// side" of this RPC channel. We maintain this variable so that
|
|
|
|
// we can detect racy RPC calls. With each RPC out-call sent, we
|
|
|
|
// send along what *we* think the stack depth of the remote side
|
|
|
|
// is *before* it will receive the RPC call.
|
|
|
|
//
|
|
|
|
// After sending the out-call, our stack depth is "incremented"
|
|
|
|
// by pushing that pending message onto mPending.
|
|
|
|
//
|
|
|
|
// Then when processing an in-call |c|, it must be true that
|
|
|
|
//
|
2009-10-08 23:21:39 -07:00
|
|
|
// mStack.size() == c.remoteDepth
|
2009-08-18 22:22:01 -07:00
|
|
|
//
|
|
|
|
// i.e., my depth is actually the same as what the other side
|
|
|
|
// thought it was when it sent in-call |c|. If this fails to
|
|
|
|
// hold, we have detected racy RPC calls.
|
|
|
|
//
|
|
|
|
// We then increment mRemoteStackDepth *just before* processing
|
|
|
|
// the in-call, since we know the other side is waiting on it, and
|
|
|
|
// decrement it *just after* finishing processing that in-call,
|
|
|
|
// since our response will pop the top of the other side's
|
|
|
|
// |mPending|.
|
|
|
|
//
|
|
|
|
// One nice aspect of this race detection is that it is symmetric;
|
|
|
|
// if one side detects a race, then the other side must also
|
|
|
|
// detect the same race.
|
|
|
|
//
|
2009-10-08 14:44:43 -07:00
|
|
|
size_t mRemoteStackDepthGuess;
|
2010-01-26 22:41:32 -08:00
|
|
|
|
|
|
|
// True iff the parent has put us in a |BlockChild()| state.
|
|
|
|
bool mBlockedOnParent;
|
2010-02-16 10:44:21 -08:00
|
|
|
|
2010-03-18 15:52:32 -07:00
|
|
|
// Approximation of Sync/RPCChannel-code frames on the C++ stack.
|
|
|
|
// It can only be interpreted as the implication
|
2010-02-16 10:44:21 -08:00
|
|
|
//
|
2010-03-18 15:52:32 -07:00
|
|
|
// !mCxxStackFrames.empty() => RPCChannel code on C++ stack
|
2010-02-16 10:44:21 -08:00
|
|
|
//
|
|
|
|
// This member is only accessed on the worker thread, and so is
|
2011-04-29 12:21:57 -07:00
|
|
|
// not protected by mMonitor. It is managed exclusively by the
|
2010-02-16 10:44:21 -08:00
|
|
|
// helper |class CxxStackFrame|.
|
2010-03-18 15:52:32 -07:00
|
|
|
std::vector<RPCFrame> mCxxStackFrames;
|
2010-03-23 22:52:47 -07:00
|
|
|
|
|
|
|
// Did we process an RPC out-call during this stack? Only
|
|
|
|
// meaningful in ExitedCxxStack(), from which this variable is
|
|
|
|
// reset.
|
|
|
|
bool mSawRPCOutMsg;
|
|
|
|
|
2010-02-14 23:47:00 -08:00
|
|
|
private:
|
|
|
|
|
|
|
|
//
|
|
|
|
// All dequeuing tasks require a single point of cancellation,
|
|
|
|
// which is handled via a reference-counted task.
|
|
|
|
//
|
|
|
|
class RefCountedTask
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RefCountedTask(CancelableTask* aTask)
|
|
|
|
: mTask(aTask)
|
|
|
|
, mRefCnt(0) {}
|
|
|
|
~RefCountedTask() { delete mTask; }
|
|
|
|
void Run() { mTask->Run(); }
|
|
|
|
void Cancel() { mTask->Cancel(); }
|
2010-03-11 14:24:15 -08:00
|
|
|
void AddRef() {
|
2011-03-28 12:58:49 -07:00
|
|
|
NS_AtomicIncrementRefcnt(mRefCnt);
|
2010-03-11 14:24:15 -08:00
|
|
|
}
|
2010-02-14 23:47:00 -08:00
|
|
|
void Release() {
|
2011-03-28 12:58:49 -07:00
|
|
|
if (NS_AtomicDecrementRefcnt(mRefCnt) == 0)
|
2010-02-14 23:47:00 -08:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CancelableTask* mTask;
|
|
|
|
nsrefcnt mRefCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Wrap an existing task which can be cancelled at any time
|
|
|
|
// without the wrapper's knowledge.
|
|
|
|
//
|
|
|
|
class DequeueTask : public Task
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DequeueTask(RefCountedTask* aTask) : mTask(aTask) {}
|
|
|
|
void Run() { mTask->Run(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<RefCountedTask> mTask;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A task encapsulating dequeuing one pending task
|
|
|
|
nsRefPtr<RefCountedTask> mDequeueOneTask;
|
2009-06-29 11:38:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif // ifndef ipc_glue_RPCChannel_h
|