OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "config.h" | 5 #include "config.h" |
6 #include "wtf/SpinLock.h" | 6 #include "wtf/SpinLock.h" |
7 | 7 |
8 #include "wtf/Atomics.h" | 8 #include "wtf/Atomics.h" |
9 #include "wtf/CPU.h" | 9 #include "wtf/CPU.h" |
10 #include "wtf/Compiler.h" | 10 #include "wtf/Compiler.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 { | 55 { |
56 // The value of kYieldProcessorTries is cargo culted from TCMalloc, Windows | 56 // The value of kYieldProcessorTries is cargo culted from TCMalloc, Windows |
57 // critical section defaults, and various other recommendations. | 57 // critical section defaults, and various other recommendations. |
58 // TODO(jschuh): Further tuning may be warranted. | 58 // TODO(jschuh): Further tuning may be warranted. |
59 static const int kYieldProcessorTries = 1000; | 59 static const int kYieldProcessorTries = 1000; |
60 do { | 60 do { |
61 do { | 61 do { |
62 for (int count = 0; count < kYieldProcessorTries; ++count) { | 62 for (int count = 0; count < kYieldProcessorTries; ++count) { |
63 // Let the Processor know we're spinning. | 63 // Let the Processor know we're spinning. |
64 YIELD_PROCESSOR; | 64 YIELD_PROCESSOR; |
65 if (!*lock && LIKELY(!atomicTestAndSetToOne(lock))) | 65 if (!noBarrierLoad(lock) && LIKELY(!atomicTestAndSetToOne(lock))
) |
66 return; | 66 return; |
67 } | 67 } |
68 | 68 |
69 // Give the OS a chance to schedule something on this core. | 69 // Give the OS a chance to schedule something on this core. |
70 YIELD_THREAD; | 70 YIELD_THREAD; |
71 } while (*lock); | 71 } while (noBarrierLoad(lock)); |
72 } while (UNLIKELY(atomicTestAndSetToOne(lock))); | 72 } while (UNLIKELY(atomicTestAndSetToOne(lock))); |
73 } | 73 } |
74 | 74 |
75 } // namespace WTF | 75 } // namespace WTF |
OLD | NEW |