diff --git a/ipc/glue/RPCChannel.cpp b/ipc/glue/RPCChannel.cpp index bab3cd345191..461c00a5fa2a 100644 --- a/ipc/glue/RPCChannel.cpp +++ b/ipc/glue/RPCChannel.cpp @@ -330,7 +330,7 @@ RPCChannel::MaybeUndeferIncall() RPC_ASSERT(mDeferred.top().rpc_remote_stack_depth_guess() <= stackDepth, "fatal logic error"); - if (mDeferred.top().rpc_remote_stack_depth_guess() < stackDepth) + if (mDeferred.top().rpc_remote_stack_depth_guess() < RemoteViewOfStackDepth(stackDepth)) return; // maybe time to process this message @@ -435,6 +435,13 @@ RPCChannel::OnMaybeDequeueOne() return true; } +size_t +RPCChannel::RemoteViewOfStackDepth(size_t stackDepth) const +{ + AssertWorkerThread(); + return stackDepth - mOutOfTurnReplies.size(); +} + void RPCChannel::Incall(const Message& call, size_t stackDepth) { @@ -445,14 +452,7 @@ RPCChannel::Incall(const Message& call, size_t stackDepth) // Race detection: see the long comment near // mRemoteStackDepthGuess in RPCChannel.h. "Remote" stack depth // means our side, and "local" means other side. - // - // We compare the remote stack depth guess against the "remote - // view of stack depth" because of 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, just - // adjust down by the number of out-of-turn replies. - size_t remoteViewOfStackDepth = (stackDepth - mOutOfTurnReplies.size()); - if (call.rpc_remote_stack_depth_guess() != remoteViewOfStackDepth) { + if (call.rpc_remote_stack_depth_guess() != RemoteViewOfStackDepth(stackDepth)) { // RPC in-calls have raced. // the "winner", if there is one, gets to defer processing of // the other side's in-call diff --git a/ipc/glue/RPCChannel.h b/ipc/glue/RPCChannel.h index 2c757f2c6607..451d50ff080e 100644 --- a/ipc/glue/RPCChannel.h +++ b/ipc/glue/RPCChannel.h @@ -207,6 +207,18 @@ protected: */ bool OnMaybeDequeueOne(); + /** + * 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; + void Incall(const Message& call, size_t stackDepth); void DispatchIncall(const Message& call);