| OLD | NEW |
| 1 /* Copyright (c) 2006, Google Inc. | 1 /* Copyright (c) 2006, Google Inc. |
| 2 * All rights reserved. | 2 * All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 static const base::LinkerInitialized LINKER_INITIALIZED; // backwards compat | 127 static const base::LinkerInitialized LINKER_INITIALIZED; // backwards compat |
| 128 private: | 128 private: |
| 129 // Lock-state: 0 means unlocked; 1 means locked with no waiters; values | 129 // Lock-state: 0 means unlocked; 1 means locked with no waiters; values |
| 130 // greater than 1 indicate locked with waiters, where the value is the time | 130 // greater than 1 indicate locked with waiters, where the value is the time |
| 131 // the first waiter started waiting and is used for contention profiling. | 131 // the first waiter started waiting and is used for contention profiling. |
| 132 volatile Atomic32 lockword_; | 132 volatile Atomic32 lockword_; |
| 133 | 133 |
| 134 void SlowLock(); | 134 void SlowLock(); |
| 135 void SlowUnlock(int64 wait_timestamp); | 135 void SlowUnlock(int64 wait_timestamp); |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(SpinLock); | 137 DISALLOW_EVIL_CONSTRUCTORS(SpinLock); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 // Corresponding locker object that arranges to acquire a spinlock for | 140 // Corresponding locker object that arranges to acquire a spinlock for |
| 141 // the duration of a C++ scope. | 141 // the duration of a C++ scope. |
| 142 class SCOPED_LOCKABLE SpinLockHolder { | 142 class SCOPED_LOCKABLE SpinLockHolder { |
| 143 private: | 143 private: |
| 144 SpinLock* lock_; | 144 SpinLock* lock_; |
| 145 public: | 145 public: |
| 146 inline explicit SpinLockHolder(SpinLock* l) EXCLUSIVE_LOCK_FUNCTION(l) | 146 inline explicit SpinLockHolder(SpinLock* l) EXCLUSIVE_LOCK_FUNCTION(l) |
| 147 : lock_(l) { | 147 : lock_(l) { |
| 148 l->Lock(); | 148 l->Lock(); |
| 149 } | 149 } |
| 150 // TODO(csilvers): uncomment the annotation when we figure out how to | 150 // TODO(csilvers): uncomment the annotation when we figure out how to |
| 151 // support this macro with 0 args (see thread_annotations.h) | 151 // support this macro with 0 args (see thread_annotations.h) |
| 152 inline ~SpinLockHolder() /*UNLOCK_FUNCTION()*/ { lock_->Unlock(); } | 152 inline ~SpinLockHolder() /*UNLOCK_FUNCTION()*/ { lock_->Unlock(); } |
| 153 }; | 153 }; |
| 154 // Catch bug where variable name is omitted, e.g. SpinLockHolder (&lock); | 154 // Catch bug where variable name is omitted, e.g. SpinLockHolder (&lock); |
| 155 #define SpinLockHolder(x) COMPILE_ASSERT(0, spin_lock_decl_missing_var_name) | 155 #define SpinLockHolder(x) COMPILE_ASSERT(0, spin_lock_decl_missing_var_name) |
| 156 | 156 |
| 157 | 157 |
| 158 #endif // BASE_SPINLOCK_H_ | 158 #endif // BASE_SPINLOCK_H_ |
| OLD | NEW |