Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: third_party/WebKit/Source/wtf/SpinLock.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "wtf/SpinLock.h" 5 #include "wtf/SpinLock.h"
6 6
7 #include "wtf/Atomics.h" 7 #include "wtf/Atomics.h"
8 #include "wtf/CPU.h" 8 #include "wtf/CPU.h"
9 #include "wtf/Compiler.h" 9 #include "wtf/Compiler.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #if OS(POSIX) 52 #if OS(POSIX)
53 #define YIELD_THREAD sched_yield() 53 #define YIELD_THREAD sched_yield()
54 #else 54 #else
55 #warning "Thread yield not supported on this OS." 55 #warning "Thread yield not supported on this OS."
56 #define YIELD_THREAD ((void)0) 56 #define YIELD_THREAD ((void)0)
57 #endif 57 #endif
58 #endif 58 #endif
59 59
60 namespace WTF { 60 namespace WTF {
61 61
62 void SpinLock::lockSlow() 62 void SpinLock::lockSlow() {
63 { 63 // The value of kYieldProcessorTries is cargo culted from TCMalloc, Windows
64 // The value of kYieldProcessorTries is cargo culted from TCMalloc, Windows 64 // critical section defaults, and various other recommendations.
65 // critical section defaults, and various other recommendations. 65 // TODO(jschuh): Further tuning may be warranted.
66 // TODO(jschuh): Further tuning may be warranted. 66 static const int kYieldProcessorTries = 1000;
67 static const int kYieldProcessorTries = 1000; 67 do {
68 do { 68 do {
69 do { 69 for (int count = 0; count < kYieldProcessorTries; ++count) {
70 for (int count = 0; count < kYieldProcessorTries; ++count) { 70 // Let the Processor know we're spinning.
71 // Let the Processor know we're spinning. 71 YIELD_PROCESSOR;
72 YIELD_PROCESSOR; 72 if (!m_lock.load(std::memory_order_relaxed) &&
73 if (!m_lock.load(std::memory_order_relaxed) && LIKELY(!m_lock.ex change(true, std::memory_order_acq_rel))) 73 LIKELY(!m_lock.exchange(true, std::memory_order_acq_rel)))
74 return; 74 return;
75 } 75 }
76 76
77 // Give the OS a chance to schedule something on this core. 77 // Give the OS a chance to schedule something on this core.
78 YIELD_THREAD; 78 YIELD_THREAD;
79 } while (m_lock.load(std::memory_order_relaxed)); 79 } while (m_lock.load(std::memory_order_relaxed));
80 } while (UNLIKELY(m_lock.exchange(true, std::memory_order_acq_rel))); 80 } while (UNLIKELY(m_lock.exchange(true, std::memory_order_acq_rel)));
81 } 81 }
82 82
83 } // namespace WTF 83 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/SpinLock.h ('k') | third_party/WebKit/Source/wtf/StaticConstructors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698