diff --git a/ipc/glue/RPCChannel.cpp b/ipc/glue/RPCChannel.cpp index 8d47ab3f3422..f4baa435527b 100644 --- a/ipc/glue/RPCChannel.cpp +++ b/ipc/glue/RPCChannel.cpp @@ -89,15 +89,13 @@ public: namespace mozilla { namespace ipc { -RPCChannel::RPCChannel(RPCListener* aListener, - RacyRPCPolicy aPolicy) +RPCChannel::RPCChannel(RPCListener* aListener) : SyncChannel(aListener), mPending(), mStack(), mOutOfTurnReplies(), mDeferred(), mRemoteStackDepthGuess(0), - mRacePolicy(aPolicy), mBlockedOnParent(false), mCxxStackFrames(0) { @@ -422,7 +420,8 @@ RPCChannel::Incall(const Message& call, size_t stackDepth) // the other side's in-call bool defer; const char* winner; - switch (mRacePolicy) { + switch (Listener()->MediateRPCRace(mChild ? call : mStack.top(), + mChild ? mStack.top() : call)) { case RRPChildWins: winner = "child"; defer = mChild; @@ -470,8 +469,7 @@ RPCChannel::DispatchIncall(const Message& call) Message* reply = nsnull; ++mRemoteStackDepthGuess; - Result rv = - static_cast(mListener)->OnCallReceived(call, reply); + Result rv = Listener()->OnCallReceived(call, reply); --mRemoteStackDepthGuess; if (!MaybeHandleError(rv, "RPCChannel")) { diff --git a/ipc/glue/RPCChannel.h b/ipc/glue/RPCChannel.h index cfe167ceb750..b36833629fd2 100644 --- a/ipc/glue/RPCChannel.h +++ b/ipc/glue/RPCChannel.h @@ -55,6 +55,13 @@ class RPCChannel : public SyncChannel friend class CxxStackFrame; public: + // What happens if RPC calls race? + enum RacyRPCPolicy { + RRPError, + RRPChildWins, + RRPParentWins + }; + class /*NS_INTERFACE_CLASS*/ RPCListener : public SyncChannel::SyncListener { @@ -78,17 +85,16 @@ public: virtual void OnExitedCxxStack() { NS_RUNTIMEABORT("default impl shouldn't be invoked"); - } + } + + virtual RacyRPCPolicy MediateRPCRace(const Message& parent, + const Message& child) + { + return RRPChildWins; + } }; - // What happens if RPC calls race? - enum RacyRPCPolicy { - RRPError, - RRPChildWins, - RRPParentWins - }; - - RPCChannel(RPCListener* aListener, RacyRPCPolicy aPolicy=RRPChildWins); + RPCChannel(RPCListener* aListener); virtual ~RPCChannel(); @@ -167,6 +173,10 @@ protected: private: // Called on worker thread only + RPCListener* Listener() const { + return static_cast(mListener); + } + bool EventOccurred(); void MaybeProcessDeferredIncall(); @@ -185,12 +195,12 @@ protected: // for when the depth goes from non-zero to zero; void EnteredCxxStack() { - static_cast(mListener)->OnEnteredCxxStack(); + Listener()->OnEnteredCxxStack(); } void ExitedCxxStack() { - static_cast(mListener)->OnExitedCxxStack(); + Listener()->OnExitedCxxStack(); } class NS_STACK_CLASS CxxStackFrame @@ -327,7 +337,6 @@ protected: // detect the same race. // size_t mRemoteStackDepthGuess; - RacyRPCPolicy mRacePolicy; // True iff the parent has put us in a |BlockChild()| state. bool mBlockedOnParent; diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 80ec3659fe03..cda8f8135eb3 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -2662,7 +2662,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): Whitespace.NL ]) self.cls.addstmts(( - [ Label.PRIVATE ] + [ Label.PUBLIC ] + self.standardTypedefs() + [ Whitespace.NL ] ))