Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Unified Diff: mojo/public/cpp/bindings/lib/connector.cc

Issue 2345013002: Mojo C++ bindings: remove the lock in MultiplexRouter if it only serves a single interface. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.cc ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/connector.cc
diff --git a/mojo/public/cpp/bindings/lib/connector.cc b/mojo/public/cpp/bindings/lib/connector.cc
index 48f4ac9cd5b3dbde193d3c2deb215a672d0b6eca..00a8580894c11d99f8e951eb07a26ada5ea6f8ea 100644
--- a/mojo/public/cpp/bindings/lib/connector.cc
+++ b/mojo/public/cpp/bindings/lib/connector.cc
@@ -12,37 +12,11 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
+#include "mojo/public/cpp/bindings/lib/may_auto_lock.h"
#include "mojo/public/cpp/bindings/sync_handle_watcher.h"
namespace mojo {
-namespace {
-
-// Similar to base::AutoLock, except that it does nothing if |lock| passed into
-// the constructor is null.
-class MayAutoLock {
- public:
- explicit MayAutoLock(base::Lock* lock) : lock_(lock) {
- if (lock_)
- lock_->Acquire();
- }
-
- ~MayAutoLock() {
- if (lock_) {
- lock_->AssertAcquired();
- lock_->Release();
- }
- }
-
- private:
- base::Lock* lock_;
- DISALLOW_COPY_AND_ASSIGN(MayAutoLock);
-};
-
-} // namespace
-
-// ----------------------------------------------------------------------------
-
Connector::Connector(ScopedMessagePipeHandle message_pipe,
ConnectorConfig config,
scoped_refptr<base::SingleThreadTaskRunner> runner)
@@ -73,7 +47,7 @@ void Connector::CloseMessagePipe() {
DCHECK(thread_checker_.CalledOnValidThread());
CancelWait();
- MayAutoLock locker(lock_.get());
+ internal::MayAutoLock locker(lock_.get());
message_pipe_.reset();
base::AutoLock lock(connected_lock_);
@@ -84,7 +58,7 @@ ScopedMessagePipeHandle Connector::PassMessagePipe() {
DCHECK(thread_checker_.CalledOnValidThread());
CancelWait();
- MayAutoLock locker(lock_.get());
+ internal::MayAutoLock locker(lock_.get());
ScopedMessagePipeHandle message_pipe = std::move(message_pipe_);
base::AutoLock lock(connected_lock_);
@@ -149,7 +123,7 @@ bool Connector::Accept(Message* message) {
if (error_)
return false;
- MayAutoLock locker(lock_.get());
+ internal::MayAutoLock locker(lock_.get());
if (!message_pipe_.is_valid() || drop_writes_)
return true;
@@ -331,7 +305,7 @@ void Connector::HandleError(bool force_pipe_reset, bool force_async_handler) {
if (force_pipe_reset) {
CancelWait();
- MayAutoLock locker(lock_.get());
+ internal::MayAutoLock locker(lock_.get());
message_pipe_.reset();
MessagePipe dummy_pipe;
message_pipe_ = std::move(dummy_pipe.handle0);
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.cc ('k') | mojo/public/cpp/bindings/lib/interface_ptr_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698