Bug 1110938 - Use message sequence number for transaction ID in MessageChannel (r=dvander)

This commit is contained in:
Bill McCloskey 2014-12-18 17:34:25 -08:00
Родитель a2ac090477
Коммит ac2be68f94
2 изменённых файлов: 10 добавлений и 33 удалений

Просмотреть файл

@ -704,23 +704,6 @@ MessageChannel::Send(Message* aMsg, Message* aReply)
IPC_ASSERT(mAwaitingSyncReplyPriority <= aMsg->priority(), IPC_ASSERT(mAwaitingSyncReplyPriority <= aMsg->priority(),
"nested sync message sends must be of increasing priority"); "nested sync message sends must be of increasing priority");
AutoSetValue<bool> replies(mAwaitingSyncReply, true);
AutoSetValue<int> prio(mAwaitingSyncReplyPriority, aMsg->priority());
AutoEnterTransaction transact(this);
aMsg->set_transaction_id(mCurrentTransaction);
if (!SendAndWait(aMsg, aReply))
return false;
NS_ABORT_IF_FALSE(aReply->is_sync(), "reply is not sync");
return true;
}
bool
MessageChannel::SendAndWait(Message* aMsg, Message* aReply)
{
mMonitor->AssertCurrentThreadOwns();
nsAutoPtr<Message> msg(aMsg); nsAutoPtr<Message> msg(aMsg);
if (!Connected()) { if (!Connected()) {
@ -733,6 +716,13 @@ MessageChannel::SendAndWait(Message* aMsg, Message* aReply)
DebugOnly<int32_t> replySeqno = msg->seqno(); DebugOnly<int32_t> replySeqno = msg->seqno();
DebugOnly<msgid_t> replyType = msg->type() + 1; DebugOnly<msgid_t> replyType = msg->type() + 1;
AutoSetValue<bool> replies(mAwaitingSyncReply, true);
AutoSetValue<int> prio(mAwaitingSyncReplyPriority, msg->priority());
AutoEnterTransaction transact(this, msg->seqno());
int32_t transaction = mCurrentTransaction;
msg->set_transaction_id(transaction);
mLink->SendMessage(msg.forget()); mLink->SendMessage(msg.forget());
while (true) { while (true) {
@ -770,6 +760,7 @@ MessageChannel::SendAndWait(Message* aMsg, Message* aReply)
MOZ_ASSERT(mRecvd->type() == replyType, "wrong reply type"); MOZ_ASSERT(mRecvd->type() == replyType, "wrong reply type");
MOZ_ASSERT(mRecvd->seqno() == replySeqno); MOZ_ASSERT(mRecvd->seqno() == replySeqno);
MOZ_ASSERT(mRecvd->is_sync());
*aReply = Move(*mRecvd); *aReply = Move(*mRecvd);
mRecvd = nullptr; mRecvd = nullptr;

Просмотреть файл

@ -211,20 +211,6 @@ class MessageChannel : HasResultCodes
// Send OnChannelConnected notification to listeners. // Send OnChannelConnected notification to listeners.
void DispatchOnChannelConnected(); void DispatchOnChannelConnected();
// Any protocol that requires blocking until a reply arrives, will send its
// outgoing message through this function. Currently, two protocols do this:
//
// sync, which can only initiate messages from child to parent.
// urgent, which can only initiate messages from parent to child.
//
// SendAndWait() expects that the worker thread owns the monitor, and that
// the message has been prepared to be sent over the link. It returns as
// soon as a reply has been received, or an error has occurred.
//
// Note that while the child is blocked waiting for a sync reply, it can wake
// up to process urgent calls from the parent.
bool SendAndWait(Message* aMsg, Message* aReply);
bool InterruptEventOccurred(); bool InterruptEventOccurred();
bool ProcessPendingRequest(const Message &aUrgent); bool ProcessPendingRequest(const Message &aUrgent);
@ -501,13 +487,13 @@ class MessageChannel : HasResultCodes
class AutoEnterTransaction class AutoEnterTransaction
{ {
public: public:
explicit AutoEnterTransaction(MessageChannel *aChan) explicit AutoEnterTransaction(MessageChannel *aChan, int32_t aMsgSeqno)
: mChan(aChan), : mChan(aChan),
mOldTransaction(mChan->mCurrentTransaction) mOldTransaction(mChan->mCurrentTransaction)
{ {
mChan->mMonitor->AssertCurrentThreadOwns(); mChan->mMonitor->AssertCurrentThreadOwns();
if (mChan->mCurrentTransaction == 0) if (mChan->mCurrentTransaction == 0)
mChan->mCurrentTransaction = mChan->NextSeqno(); mChan->mCurrentTransaction = aMsgSeqno;
} }
explicit AutoEnterTransaction(MessageChannel *aChan, const Message &aMessage) explicit AutoEnterTransaction(MessageChannel *aChan, const Message &aMessage)
: mChan(aChan), : mChan(aChan),