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