mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1719577 - Part 1: Use inline initializers for MessageChannel fields, r=handyman
This makes things generally more clear, and avoids a long list of initializers in the MessageChannel constructor. In addition, some fields which are never modified are marked as `const`. Differential Revision: https://phabricator.services.mozilla.com/D119349
This commit is contained in:
parent
405247cb61
commit
488fc0d1be
@ -143,8 +143,6 @@ static const uint32_t kMinTelemetryIPCWriteLatencyMs = 1;
|
||||
// (IPC_SYNC_MAIN_LATENCY_MS and IPC_SYNC_RECEIVE_MS).
|
||||
static const uint32_t kMinTelemetrySyncIPCLatencyMs = 1;
|
||||
|
||||
const int32_t MessageChannel::kNoTimeout = INT32_MIN;
|
||||
|
||||
// static
|
||||
bool MessageChannel::sIsPumpingMessages = false;
|
||||
|
||||
@ -571,37 +569,10 @@ static void TryRegisterStrongMemoryReporter() {
|
||||
Atomic<size_t> MessageChannel::gUnresolvedResponses;
|
||||
|
||||
MessageChannel::MessageChannel(const char* aName, IToplevelProtocol* aListener)
|
||||
: mName(aName),
|
||||
mListener(aListener),
|
||||
mChannelState(ChannelClosed),
|
||||
mSide(UnknownSide),
|
||||
mIsCrossProcess(false),
|
||||
mChannelErrorTask(nullptr),
|
||||
mTimeoutMs(kNoTimeout),
|
||||
mInTimeoutSecondHalf(false),
|
||||
mNextSeqno(0),
|
||||
mLastSendError(SyncSendError::SendSuccess),
|
||||
mDispatchingAsyncMessage(false),
|
||||
mDispatchingAsyncMessageNestedLevel(0),
|
||||
mTransactionStack(nullptr),
|
||||
mTimedOutMessageSeqno(0),
|
||||
mTimedOutMessageNestedLevel(0),
|
||||
mMaybeDeferredPendingCount(0),
|
||||
mRemoteStackDepthGuess(0),
|
||||
mSawInterruptOutMsg(false),
|
||||
mIsWaitingForIncoming(false),
|
||||
mAbortOnError(false),
|
||||
mNotifiedChannelDone(false),
|
||||
mFlags(REQUIRE_DEFAULT),
|
||||
mIsPostponingSends(false),
|
||||
mBuildIDsConfirmedMatch(false),
|
||||
mIsSameThreadChannel(false) {
|
||||
: mName(aName), mListener(aListener) {
|
||||
MOZ_COUNT_CTOR(ipc::MessageChannel);
|
||||
|
||||
#ifdef OS_WIN
|
||||
mTopFrame = nullptr;
|
||||
mIsSyncWaitingOnNonMainThread = false;
|
||||
|
||||
mEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
|
||||
MOZ_RELEASE_ASSERT(mEvent, "CreateEvent failed! Nothing is going to work!");
|
||||
#endif
|
||||
|
@ -147,7 +147,7 @@ class MessageChannel : HasResultCodes {
|
||||
friend class PendingResponseReporter;
|
||||
|
||||
public:
|
||||
static const int32_t kNoTimeout;
|
||||
static constexpr int32_t kNoTimeout = INT32_MIN;
|
||||
|
||||
typedef IPC::Message Message;
|
||||
typedef IPC::MessageInfo MessageInfo;
|
||||
@ -360,9 +360,9 @@ class MessageChannel : HasResultCodes {
|
||||
|
||||
protected:
|
||||
// The deepest sync stack frame for this channel.
|
||||
SyncStackFrame* mTopFrame;
|
||||
SyncStackFrame* mTopFrame = nullptr;
|
||||
|
||||
bool mIsSyncWaitingOnNonMainThread;
|
||||
bool mIsSyncWaitingOnNonMainThread = false;
|
||||
|
||||
// The deepest sync stack frame on any channel.
|
||||
static SyncStackFrame* sStaticTopFrame;
|
||||
@ -595,18 +595,25 @@ class MessageChannel : HasResultCodes {
|
||||
|
||||
private:
|
||||
// This will be a string literal, so lifetime is not an issue.
|
||||
const char* mName;
|
||||
const char* const mName;
|
||||
|
||||
// Based on presumption the listener owns and overlives the channel,
|
||||
// this is never nullified.
|
||||
IToplevelProtocol* mListener;
|
||||
ChannelState mChannelState;
|
||||
IToplevelProtocol* const mListener;
|
||||
|
||||
// This monitor guards all state in this MessageChannel, except where
|
||||
// otherwise noted. It is refcounted so a reference to it can be shared with
|
||||
// IPC listener objects which need to access weak references to this
|
||||
// `MessageChannel`.
|
||||
RefPtr<RefCountedMonitor> mMonitor;
|
||||
Side mSide;
|
||||
bool mIsCrossProcess;
|
||||
|
||||
ChannelState mChannelState = ChannelClosed;
|
||||
Side mSide = UnknownSide;
|
||||
bool mIsCrossProcess = false;
|
||||
UniquePtr<MessageLink> mLink;
|
||||
RefPtr<CancelableRunnable>
|
||||
mChannelErrorTask; // NotifyMaybeChannelError runnable
|
||||
|
||||
// NotifyMaybeChannelError runnable
|
||||
RefPtr<CancelableRunnable> mChannelErrorTask;
|
||||
|
||||
// Thread we are allowed to send and receive on.
|
||||
nsCOMPtr<nsISerialEventTarget> mWorkerThread;
|
||||
@ -615,17 +622,17 @@ class MessageChannel : HasResultCodes {
|
||||
// triggering an abort. This method (called by WaitForEvent with a 'did
|
||||
// timeout' flag) decides if we should wait again for half of mTimeoutMs
|
||||
// or give up.
|
||||
int32_t mTimeoutMs;
|
||||
bool mInTimeoutSecondHalf;
|
||||
int32_t mTimeoutMs = kNoTimeout;
|
||||
bool mInTimeoutSecondHalf = false;
|
||||
|
||||
// Worker-thread only; sequence numbers for messages that require
|
||||
// replies.
|
||||
int32_t mNextSeqno;
|
||||
int32_t mNextSeqno = 0;
|
||||
|
||||
static bool sIsPumpingMessages;
|
||||
|
||||
// If ::Send returns false, this gives a more descriptive error.
|
||||
SyncSendError mLastSendError;
|
||||
SyncSendError mLastSendError = SyncSendError::SendSuccess;
|
||||
|
||||
template <class T>
|
||||
class AutoSetValue {
|
||||
@ -649,8 +656,8 @@ class MessageChannel : HasResultCodes {
|
||||
T mNew;
|
||||
};
|
||||
|
||||
bool mDispatchingAsyncMessage;
|
||||
int mDispatchingAsyncMessageNestedLevel;
|
||||
bool mDispatchingAsyncMessage = false;
|
||||
int mDispatchingAsyncMessageNestedLevel = 0;
|
||||
|
||||
// When we send an urgent request from the parent process, we could race
|
||||
// with an RPC message that was issued by the child beforehand. In this
|
||||
@ -671,7 +678,7 @@ class MessageChannel : HasResultCodes {
|
||||
// which grow in opposite directions from child to parent.
|
||||
|
||||
friend class AutoEnterTransaction;
|
||||
AutoEnterTransaction* mTransactionStack;
|
||||
AutoEnterTransaction* mTransactionStack = nullptr;
|
||||
|
||||
int32_t CurrentNestedInsideSyncTransaction() const;
|
||||
|
||||
@ -700,8 +707,8 @@ class MessageChannel : HasResultCodes {
|
||||
// A message is only timed out if it initiated a transaction. This avoids
|
||||
// hitting a lot of corner cases with message nesting that we don't really
|
||||
// care about.
|
||||
int32_t mTimedOutMessageSeqno;
|
||||
int mTimedOutMessageNestedLevel;
|
||||
int32_t mTimedOutMessageSeqno = 0;
|
||||
int mTimedOutMessageNestedLevel = 0;
|
||||
|
||||
// Queue of all incoming messages.
|
||||
//
|
||||
@ -743,7 +750,7 @@ class MessageChannel : HasResultCodes {
|
||||
// The number of messages in mPending for which IsAlwaysDeferred is false
|
||||
// (i.e., the number of messages that might not be deferred, depending on
|
||||
// context).
|
||||
size_t mMaybeDeferredPendingCount;
|
||||
size_t mMaybeDeferredPendingCount = 0;
|
||||
|
||||
// Stack of all the out-calls on which this channel is awaiting responses.
|
||||
// Each stack refers to a different protocol and the stacks are mutually
|
||||
@ -775,7 +782,7 @@ class MessageChannel : HasResultCodes {
|
||||
//
|
||||
// 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.
|
||||
size_t mRemoteStackDepthGuess;
|
||||
size_t mRemoteStackDepthGuess = 0;
|
||||
|
||||
// Approximation of code frames on the C++ stack. It can only be
|
||||
// interpreted as the implication:
|
||||
@ -789,12 +796,12 @@ class MessageChannel : HasResultCodes {
|
||||
|
||||
// Did we process an Interrupt out-call during this stack? Only meaningful in
|
||||
// ExitedCxxStack(), from which this variable is reset.
|
||||
bool mSawInterruptOutMsg;
|
||||
bool mSawInterruptOutMsg = false;
|
||||
|
||||
// Are we waiting on this channel for an incoming message? This is used
|
||||
// to implement WaitForIncomingMessage(). Must only be accessed while owning
|
||||
// mMonitor.
|
||||
bool mIsWaitingForIncoming;
|
||||
bool mIsWaitingForIncoming = false;
|
||||
|
||||
// Map of replies received "out of turn", because of Interrupt
|
||||
// in-calls racing with replies to outstanding in-calls. See
|
||||
@ -814,25 +821,25 @@ class MessageChannel : HasResultCodes {
|
||||
|
||||
// Should the channel abort the process from the I/O thread when
|
||||
// a channel error occurs?
|
||||
bool mAbortOnError;
|
||||
bool mAbortOnError = false;
|
||||
|
||||
// True if the listener has already been notified of a channel close or
|
||||
// error.
|
||||
bool mNotifiedChannelDone;
|
||||
bool mNotifiedChannelDone = false;
|
||||
|
||||
// See SetChannelFlags
|
||||
ChannelFlags mFlags;
|
||||
ChannelFlags mFlags = REQUIRE_DEFAULT;
|
||||
|
||||
// Channels can enter messages are not sent immediately; instead, they are
|
||||
// held in a queue until another thread deems it is safe to send them.
|
||||
bool mIsPostponingSends;
|
||||
bool mIsPostponingSends = false;
|
||||
std::vector<UniquePtr<Message>> mPostponedSends;
|
||||
|
||||
bool mBuildIDsConfirmedMatch;
|
||||
bool mBuildIDsConfirmedMatch = false;
|
||||
|
||||
// If this is true, both ends of this message channel have event targets
|
||||
// on the same thread.
|
||||
bool mIsSameThreadChannel;
|
||||
bool mIsSameThreadChannel = false;
|
||||
};
|
||||
|
||||
void CancelCPOWs();
|
||||
|
Loading…
Reference in New Issue
Block a user