Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |