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

Side by Side Diff: base/synchronization/lock.h

Issue 14387002: Adding TryPostTask to the message loop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bool Created 7 years, 8 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 | Annotate | Revision Log
« base/message_loop_unittest.cc ('K') | « base/message_loop_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_SYNCHRONIZATION_LOCK_H_ 5 #ifndef BASE_SYNCHRONIZATION_LOCK_H_
6 #define BASE_SYNCHRONIZATION_LOCK_H_ 6 #define BASE_SYNCHRONIZATION_LOCK_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/synchronization/lock_impl.h" 9 #include "base/synchronization/lock_impl.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 // Platform specific underlying lock implementation. 90 // Platform specific underlying lock implementation.
91 internal::LockImpl lock_; 91 internal::LockImpl lock_;
92 92
93 DISALLOW_COPY_AND_ASSIGN(Lock); 93 DISALLOW_COPY_AND_ASSIGN(Lock);
94 }; 94 };
95 95
96 // A helper class that acquires the given Lock while the AutoLock is in scope. 96 // A helper class that acquires the given Lock while the AutoLock is in scope.
97 class AutoLock { 97 class AutoLock {
98 public: 98 public:
99 struct NoAcquire {};
jar (doing other things) 2013/04/26 21:59:43 I have a habit (religion?) of avoiding a negative
100
99 explicit AutoLock(Lock& lock) : lock_(lock) { 101 explicit AutoLock(Lock& lock) : lock_(lock) {
100 lock_.Acquire(); 102 lock_.Acquire();
101 } 103 }
102 104
105 AutoLock(Lock& lock, const NoAcquire&) : lock_(lock) {
106 }
jar (doing other things) 2013/04/21 15:29:35 If you stick with this API... I'd suggest: lock_.
107
103 ~AutoLock() { 108 ~AutoLock() {
104 lock_.AssertAcquired(); 109 lock_.AssertAcquired();
105 lock_.Release(); 110 lock_.Release();
106 } 111 }
107 112
108 private: 113 private:
109 Lock& lock_; 114 Lock& lock_;
110 DISALLOW_COPY_AND_ASSIGN(AutoLock); 115 DISALLOW_COPY_AND_ASSIGN(AutoLock);
111 }; 116 };
112 117
(...skipping 12 matching lines...) Expand all
125 } 130 }
126 131
127 private: 132 private:
128 Lock& lock_; 133 Lock& lock_;
129 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); 134 DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
130 }; 135 };
131 136
132 } // namespace base 137 } // namespace base
133 138
134 #endif // BASE_SYNCHRONIZATION_LOCK_H_ 139 #endif // BASE_SYNCHRONIZATION_LOCK_H_
OLDNEW
« base/message_loop_unittest.cc ('K') | « base/message_loop_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698