Chromium Code Reviews| Index: third_party/tcmalloc/chromium/src/gperftools/spin_lock_wrapper.h |
| diff --git a/third_party/tcmalloc/chromium/src/gperftools/spin_lock_wrapper.h b/third_party/tcmalloc/chromium/src/gperftools/spin_lock_wrapper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c2f604ffafed93039475b8f3d5bf98a626c167bd |
| --- /dev/null |
| +++ b/third_party/tcmalloc/chromium/src/gperftools/spin_lock_wrapper.h |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SPINLOCK_WRAPPER_H_ |
| +#define SPINLOCK_WRAPPER_H_ |
| + |
| +class SpinLock; |
| + |
| +// A container class for using tcmalloc's SpinLock class. |
| +// This avoids users of this class to directly include those classes, causing |
|
jar (doing other things)
2015/08/21 02:48:43
nit: typos in sentence. I don't know what you mea
Simon Que
2015/08/21 21:59:20
Done.
|
| +// #include path conflicts. |
| + |
| +// SpinLockWrapper depends on CustomAllocator, which must be initialized before |
| +// any instance of this class is created. |
| +class SpinLockWrapper { |
| + public: |
| + SpinLockWrapper(); |
| + ~SpinLockWrapper(); |
| + |
| + void Lock(); |
| + void Unlock(); |
| + |
| + private: |
| + SpinLock* lock_; |
| +}; |
| + |
| +// Corresponding locker object that arranges to acquire a spinlock for the |
| +// duration of a C++ scope. |
| +class ScopedSpinLockHolder { |
| + public: |
| + explicit ScopedSpinLockHolder(SpinLockWrapper* lock) : lock_(lock) { |
| + lock_->Lock(); |
| + } |
| + |
| + ~ScopedSpinLockHolder() { |
| + lock_->Unlock(); |
| + } |
| + |
| + private: |
| + SpinLockWrapper* lock_; |
| +}; |
| + |
| +#endif // SPINLOCK_WRAPPER_H_ |