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

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

Issue 1463683002: Switch wtf/SpinLock to std::atomic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync again Created 5 years 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 "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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #if OS(POSIX) 46 #if OS(POSIX)
47 #define YIELD_THREAD sched_yield() 47 #define YIELD_THREAD sched_yield()
48 #else 48 #else
49 #warning "Thread yield not supported on this OS." 49 #warning "Thread yield not supported on this OS."
50 #define YIELD_THREAD ((void)0) 50 #define YIELD_THREAD ((void)0)
51 #endif 51 #endif
52 #endif 52 #endif
53 53
54 namespace WTF { 54 namespace WTF {
55 55
56 void slowSpinLockLock(int volatile* lock) 56 void SpinLock::SlowLock()
57 { 57 {
58 // The value of kYieldProcessorTries is cargo culted from TCMalloc, Windows 58 // The value of kYieldProcessorTries is cargo culted from TCMalloc, Windows
59 // critical section defaults, and various other recommendations. 59 // critical section defaults, and various other recommendations.
60 // TODO(jschuh): Further tuning may be warranted. 60 // TODO(jschuh): Further tuning may be warranted.
61 static const int kYieldProcessorTries = 1000; 61 static const int kYieldProcessorTries = 1000;
62 do { 62 do {
63 do { 63 do {
64 for (int count = 0; count < kYieldProcessorTries; ++count) { 64 for (int count = 0; count < kYieldProcessorTries; ++count) {
65 // Let the Processor know we're spinning. 65 // Let the Processor know we're spinning.
66 YIELD_PROCESSOR; 66 YIELD_PROCESSOR;
67 if (!*lock && LIKELY(!atomicTestAndSetToOne(lock))) 67 if (!m_lock.load() && LIKELY(!m_lock.exchange(true)))
Alexander Potapenko 2015/12/04 12:17:34 load() can be made memory_order_relaxed, and excha
jschuh 2015/12/04 20:45:13 Done.
68 return; 68 return;
69 } 69 }
70 70
71 // Give the OS a chance to schedule something on this core. 71 // Give the OS a chance to schedule something on this core.
72 YIELD_THREAD; 72 YIELD_THREAD;
73 } while (*lock); 73 } while (m_lock.exchange(true));
Alexander Potapenko 2015/12/04 12:17:34 memory_order_acq_rel
jschuh 2015/12/04 20:45:13 Actually, this was a mistake on my part and should
74 } while (UNLIKELY(atomicTestAndSetToOne(lock))); 74 } while (UNLIKELY(m_lock.exchange(true)));
Alexander Potapenko 2015/12/04 12:17:34 ditto.
jschuh 2015/12/04 20:45:13 Done.
75 } 75 }
76 76
77 } // namespace WTF 77 } // namespace WTF
OLDNEW
« third_party/WebKit/Source/wtf/SpinLock.h ('K') | « third_party/WebKit/Source/wtf/SpinLock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698