| Index: third_party/mojo/src/mojo/edk/system/channel.h
|
| diff --git a/third_party/mojo/src/mojo/edk/system/channel.h b/third_party/mojo/src/mojo/edk/system/channel.h
|
| index 015fa7374093261e0cad9b45776a91176245a339..9b7c3ae2badbfe0dd2fe3513096da8c37162007f 100644
|
| --- a/third_party/mojo/src/mojo/edk/system/channel.h
|
| +++ b/third_party/mojo/src/mojo/edk/system/channel.h
|
| @@ -10,13 +10,13 @@
|
| #include "base/containers/hash_tables.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "base/synchronization/lock.h"
|
| #include "base/threading/thread_checker.h"
|
| #include "mojo/edk/embedder/scoped_platform_handle.h"
|
| #include "mojo/edk/system/channel_endpoint.h"
|
| #include "mojo/edk/system/channel_endpoint_id.h"
|
| #include "mojo/edk/system/incoming_endpoint.h"
|
| #include "mojo/edk/system/message_in_transit.h"
|
| +#include "mojo/edk/system/mutex.h"
|
| #include "mojo/edk/system/raw_channel.h"
|
| #include "mojo/edk/system/system_impl_export.h"
|
| #include "mojo/public/c/system/types.h"
|
| @@ -59,7 +59,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel final
|
| // This must be called on the creation thread before any other methods are
|
| // called, and before references to this object are given to any other
|
| // threads. |raw_channel| should be uninitialized.
|
| - void Init(scoped_ptr<RawChannel> raw_channel);
|
| + void Init(scoped_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE;
|
|
|
| // Sets the channel manager associated with this channel. This should be set
|
| // at most once and only called before |WillShutdownSoon()| (and
|
| @@ -220,47 +220,51 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel final
|
| ChannelEndpointId AttachAndRunEndpoint(
|
| scoped_refptr<ChannelEndpoint> endpoint);
|
|
|
| - // Helper to send channel control messages. Returns true on success. Should be
|
| - // called *without* |lock_| held. Callable from any thread.
|
| + // Helper to send channel control messages. Returns true on success. Callable
|
| + // from any thread.
|
| bool SendControlMessage(MessageInTransit::Subtype subtype,
|
| ChannelEndpointId source_id,
|
| - ChannelEndpointId destination_id);
|
| + ChannelEndpointId destination_id)
|
| + MOJO_LOCKS_EXCLUDED(mutex_);
|
|
|
| base::ThreadChecker creation_thread_checker_;
|
|
|
| embedder::PlatformSupport* const platform_support_;
|
|
|
| // Note: |ChannelEndpointClient|s (in particular, |MessagePipe|s) MUST NOT be
|
| - // used under |lock_|. E.g., |lock_| can only be acquired after
|
| + // used under |mutex_|. E.g., |mutex_| can only be acquired after
|
| // |MessagePipe::lock_|, never before. Thus to call into a
|
| // |ChannelEndpointClient|, a reference should be acquired from
|
| - // |local_id_to_endpoint_map_| under |lock_| and then the lock released.
|
| - base::Lock lock_; // Protects the members below.
|
| -
|
| - scoped_ptr<RawChannel> raw_channel_;
|
| - bool is_running_;
|
| + // |local_id_to_endpoint_map_| under |mutex_| and then the lock released.
|
| + // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|,
|
| + // once clang actually checks such annotations.
|
| + // https://github.com/domokit/mojo/issues/313
|
| + mutable Mutex mutex_;
|
| +
|
| + scoped_ptr<RawChannel> raw_channel_ MOJO_GUARDED_BY(mutex_);
|
| + bool is_running_ MOJO_GUARDED_BY(mutex_);
|
| // Set when |WillShutdownSoon()| is called.
|
| - bool is_shutting_down_;
|
| + bool is_shutting_down_ MOJO_GUARDED_BY(mutex_);
|
|
|
| // Has a reference to us.
|
| - ChannelManager* channel_manager_;
|
| + ChannelManager* channel_manager_ MOJO_GUARDED_BY(mutex_);
|
|
|
| using IdToEndpointMap =
|
| base::hash_map<ChannelEndpointId, scoped_refptr<ChannelEndpoint>>;
|
| // Map from local IDs to endpoints. If the endpoint is null, this means that
|
| // we're just waiting for the remove ack before removing the entry.
|
| - IdToEndpointMap local_id_to_endpoint_map_;
|
| + IdToEndpointMap local_id_to_endpoint_map_ MOJO_GUARDED_BY(mutex_);
|
| // Note: The IDs generated by this should be checked for existence before use.
|
| - LocalChannelEndpointIdGenerator local_id_generator_;
|
| + LocalChannelEndpointIdGenerator local_id_generator_ MOJO_GUARDED_BY(mutex_);
|
|
|
| using IdToIncomingEndpointMap =
|
| base::hash_map<ChannelEndpointId, scoped_refptr<IncomingEndpoint>>;
|
| // Map from local IDs to incoming endpoints (i.e., those received inside other
|
| // messages, but not yet claimed via |DeserializeEndpoint()|).
|
| - IdToIncomingEndpointMap incoming_endpoints_;
|
| + IdToIncomingEndpointMap incoming_endpoints_ MOJO_GUARDED_BY(mutex_);
|
| // TODO(vtl): We need to keep track of remote IDs (so that we don't collide
|
| // if/when we wrap).
|
| - RemoteChannelEndpointIdGenerator remote_id_generator_;
|
| + RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_);
|
|
|
| MOJO_DISALLOW_COPY_AND_ASSIGN(Channel);
|
| };
|
|
|