OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #ifndef SPINLOCK_WRAPPER_H_ | |
6 #define SPINLOCK_WRAPPER_H_ | |
7 | |
8 class SpinLock; | |
9 | |
10 // A container class for using tcmalloc's SpinLock class. | |
11 // 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.
| |
12 // #include path conflicts. | |
13 | |
14 // SpinLockWrapper depends on CustomAllocator, which must be initialized before | |
15 // any instance of this class is created. | |
16 class SpinLockWrapper { | |
17 public: | |
18 SpinLockWrapper(); | |
19 ~SpinLockWrapper(); | |
20 | |
21 void Lock(); | |
22 void Unlock(); | |
23 | |
24 private: | |
25 SpinLock* lock_; | |
26 }; | |
27 | |
28 // Corresponding locker object that arranges to acquire a spinlock for the | |
29 // duration of a C++ scope. | |
30 class ScopedSpinLockHolder { | |
31 public: | |
32 explicit ScopedSpinLockHolder(SpinLockWrapper* lock) : lock_(lock) { | |
33 lock_->Lock(); | |
34 } | |
35 | |
36 ~ScopedSpinLockHolder() { | |
37 lock_->Unlock(); | |
38 } | |
39 | |
40 private: | |
41 SpinLockWrapper* lock_; | |
42 }; | |
43 | |
44 #endif // SPINLOCK_WRAPPER_H_ | |
OLD | NEW |