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

Side by Side Diff: mojo/public/cpp/bindings/lib/may_auto_lock.h

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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/synchronization/lock.h"
7
8 namespace mojo {
9 namespace internal {
10
11 // Similar to base::AutoLock, except that it does nothing if |lock| passed into
12 // the constructor is null.
13 class MayAutoLock {
14 public:
15 explicit MayAutoLock(base::Lock* lock) : lock_(lock) {
16 if (lock_)
17 lock_->Acquire();
18 }
19
20 ~MayAutoLock() {
21 if (lock_) {
22 lock_->AssertAcquired();
23 lock_->Release();
24 }
25 }
26
27 private:
28 base::Lock* lock_;
29 DISALLOW_COPY_AND_ASSIGN(MayAutoLock);
30 };
31
32 // Similar to base::AutoUnlock, except that it does nothing if |lock| passed
33 // into the constructor is null.
34 class MayAutoUnlock {
35 public:
36 explicit MayAutoUnlock(base::Lock* lock) : lock_(lock) {
37 if (lock_) {
38 lock_->AssertAcquired();
39 lock_->Release();
40 }
41 }
42
43 ~MayAutoUnlock() {
44 if (lock_)
45 lock_->Acquire();
46 }
47
48 private:
49 base::Lock* lock_;
50 DISALLOW_COPY_AND_ASSIGN(MayAutoUnlock);
51 };
52
53 } // namespace internal
54 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_ptr_state.h ('k') | mojo/public/cpp/bindings/lib/multiplex_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698