Chromium Code Reviews| Index: mojo/public/cpp/bindings/lib/connector.h |
| diff --git a/mojo/public/cpp/bindings/lib/connector.h b/mojo/public/cpp/bindings/lib/connector.h |
| index 185a98446d015810a0b91e2cf813459bb63e2d2b..6cfbbf7ade43f0036698d86d0e8556a1c23c2387 100644 |
| --- a/mojo/public/cpp/bindings/lib/connector.h |
| +++ b/mojo/public/cpp/bindings/lib/connector.h |
| @@ -5,15 +5,18 @@ |
| #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| +#include "base/memory/scoped_ptr.h" |
| #include "mojo/public/c/environment/async_waiter.h" |
| #include "mojo/public/cpp/bindings/callback.h" |
| #include "mojo/public/cpp/bindings/message.h" |
| #include "mojo/public/cpp/environment/environment.h" |
| #include "mojo/public/cpp/system/core.h" |
| -namespace mojo { |
| -class ErrorHandler; |
| +namespace base { |
| +class Lock; |
| +} |
| +namespace mojo { |
| namespace internal { |
| // The Connector class is responsible for performing read/write operations on a |
| @@ -21,13 +24,21 @@ namespace internal { |
| // interface that it subclasses, and it forwards messages it reads through the |
| // MessageReceiver interface assigned as its incoming receiver. |
| // |
| -// NOTE: MessagePipe I/O is non-blocking. |
| -// |
| +// NOTE: |
| +// - MessagePipe I/O is non-blocking. |
| +// - Sending messages can be configured to be thread safe (please see comments |
|
sky
2015/11/19 17:16:26
Can you use threading asserts to verify this(Threa
yzshen1
2015/11/19 22:00:40
Done.
|
| +// of the constructor). Other than that, the object should only be accessed |
| +// on the creating thread. |
| class Connector : public MessageReceiver { |
| public: |
| + enum SendingThreadSaftyType { SINGLE_THREADED_SEND, MULTI_THREADED_SEND }; |
|
sky
2015/11/19 17:16:27
nit: enum class
yzshen1
2015/11/19 22:00:40
Currently I refer to the values at the callsites u
sky
2015/11/20 01:00:19
Would using address that?
Part of this is because
yzshen1
2015/11/20 17:01:00
Using doesn't help in this case unfortunately.
|
| + |
| // The Connector takes ownership of |message_pipe|. |
| - explicit Connector( |
| + // If |sending_thread_safty_type| is set to MULTI_THREADED_SEND, Accept() is |
|
sky
2015/11/19 17:16:27
safty->safety
yzshen1
2015/11/19 22:00:40
Ah, sorry. :)
|
| + // safe to call from multiple threads. |
| + Connector( |
| ScopedMessagePipeHandle message_pipe, |
| + SendingThreadSaftyType sending_thread_safty_type, |
| const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()); |
| ~Connector() override; |
| @@ -133,6 +144,10 @@ class Connector : public MessageReceiver { |
| // of dispatching an incoming message. |
| bool* destroyed_flag_; |
| + // If sending messages is allowed from multiple threads, |lock_| is used to |
| + // protect modifications to |message_pipe_| and |drop_writes_|. |
| + scoped_ptr<base::Lock> lock_; |
| + |
| MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); |
| }; |