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

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
Ken Rockot(use gerrit already) 2016/09/15 20:21:41 nit: weird formatting
yzshen1 2016/09/15 21:24:59 Done. I guess git cl format is not smart enough!
34 // the constructor is null.
35 class MayAutoUnlock {
36 public:
37 explicit MayAutoUnlock(base::Lock* lock) : lock_(lock) {
38 if (lock_) {
39 lock_->AssertAcquired();
40 lock_->Release();
41 }
42 }
43
44 ~MayAutoUnlock() {
45 if (lock_)
46 lock_->Acquire();
47 }
48
49 private:
50 base::Lock* lock_;
51 DISALLOW_COPY_AND_ASSIGN(MayAutoUnlock);
52 };
53
54 } // namespace internal
55 } // 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