| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_LOCK_H_ | 5 #ifndef BASE_LOCK_H_ |
| 6 #define BASE_LOCK_H_ | 6 #define BASE_LOCK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/lock_impl.h" | 9 #include "base/lock_impl.h" |
| 10 #include "base/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 11 | 11 |
| 12 // A convenient wrapper for an OS specific critical section. The only real | 12 // A convenient wrapper for an OS specific critical section. The only real |
| 13 // intelligence in this class is in debug mode for the support for the | 13 // intelligence in this class is in debug mode for the support for the |
| 14 // AssertAcquired() method. | 14 // AssertAcquired() method. |
| 15 | 15 |
| 16 class Lock { | 16 class Lock { |
| 17 public: | 17 public: |
| 18 #if defined(NDEBUG) // Optimized wrapper implementation | 18 #if defined(NDEBUG) // Optimized wrapper implementation |
| 19 Lock() : lock_() {} | 19 Lock() : lock_() {} |
| 20 ~Lock() {} | 20 ~Lock() {} |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // It's worth it to share the code. | 73 // It's worth it to share the code. |
| 74 void CheckHeldAndUnmark(); | 74 void CheckHeldAndUnmark(); |
| 75 void CheckUnheldAndMark(); | 75 void CheckUnheldAndMark(); |
| 76 | 76 |
| 77 // All private data is implicitly protected by lock_. | 77 // All private data is implicitly protected by lock_. |
| 78 // Be VERY careful to only access members under that lock. | 78 // Be VERY careful to only access members under that lock. |
| 79 | 79 |
| 80 // Determines validity of owning_thread_id_. Needed as we don't have | 80 // Determines validity of owning_thread_id_. Needed as we don't have |
| 81 // a null owning_thread_id_ value. | 81 // a null owning_thread_id_ value. |
| 82 bool owned_by_thread_; | 82 bool owned_by_thread_; |
| 83 PlatformThreadId owning_thread_id_; | 83 base::PlatformThreadId owning_thread_id_; |
| 84 #endif // NDEBUG | 84 #endif // NDEBUG |
| 85 | 85 |
| 86 LockImpl lock_; // Platform specific underlying lock implementation. | 86 LockImpl lock_; // Platform specific underlying lock implementation. |
| 87 | 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(Lock); | 88 DISALLOW_COPY_AND_ASSIGN(Lock); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 // A helper class that acquires the given Lock while the AutoLock is in scope. | 91 // A helper class that acquires the given Lock while the AutoLock is in scope. |
| 92 class AutoLock { | 92 class AutoLock { |
| 93 public: | 93 public: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 118 ~AutoUnlock() { | 118 ~AutoUnlock() { |
| 119 lock_.Acquire(); | 119 lock_.Acquire(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 Lock& lock_; | 123 Lock& lock_; |
| 124 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); | 124 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 #endif // BASE_LOCK_H_ | 127 #endif // BASE_LOCK_H_ |
| OLD | NEW |