Title: [188717] trunk/Source/WTF
- Revision
- 188717
- Author
- [email protected]
- Date
- 2015-08-20 17:00:29 -0700 (Thu, 20 Aug 2015)
Log Message
Merge Lock and LockBase
https://bugs.webkit.org/show_bug.cgi?id=148266
Reviewed by Filip Pizlo.
* wtf/Atomics.h:
(WTF::Atomic::Atomic):
Add a default constructor as well as a constexpr constructor that takes a value.
* wtf/Lock.cpp:
(WTF::Lock::lockSlow):
(WTF::Lock::unlockSlow):
Rename LockBase to Lock.
* wtf/Lock.h:
Rename LockBase to Lock and direct-initialize Atomic to 0. Since the Atomic constructor is constexpr,
Lock also gets a constexpr constructor. Change the LockBase -> StaticLock typedef and add a fixme.
* wtf/WordLock.h:
Direct initialize m_word to 0.
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (188716 => 188717)
--- trunk/Source/WTF/ChangeLog 2015-08-20 23:06:13 UTC (rev 188716)
+++ trunk/Source/WTF/ChangeLog 2015-08-21 00:00:29 UTC (rev 188717)
@@ -1,3 +1,26 @@
+2015-08-20 Anders Carlsson <[email protected]>
+
+ Merge Lock and LockBase
+ https://bugs.webkit.org/show_bug.cgi?id=148266
+
+ Reviewed by Filip Pizlo.
+
+ * wtf/Atomics.h:
+ (WTF::Atomic::Atomic):
+ Add a default constructor as well as a constexpr constructor that takes a value.
+
+ * wtf/Lock.cpp:
+ (WTF::Lock::lockSlow):
+ (WTF::Lock::unlockSlow):
+ Rename LockBase to Lock.
+
+ * wtf/Lock.h:
+ Rename LockBase to Lock and direct-initialize Atomic to 0. Since the Atomic constructor is constexpr,
+ Lock also gets a constexpr constructor. Change the LockBase -> StaticLock typedef and add a fixme.
+
+ * wtf/WordLock.h:
+ Direct initialize m_word to 0.
+
2015-08-19 Filip Pizlo <[email protected]>
Remove WTF::SpinLock
Modified: trunk/Source/WTF/wtf/Atomics.h (188716 => 188717)
--- trunk/Source/WTF/wtf/Atomics.h 2015-08-20 23:06:13 UTC (rev 188716)
+++ trunk/Source/WTF/wtf/Atomics.h 2015-08-21 00:00:29 UTC (rev 188717)
@@ -81,6 +81,12 @@
template<typename T>
struct Atomic {
+ Atomic() = default;
+ CONSTEXPR Atomic(T value)
+ : value(value)
+ {
+ }
+
// Don't pass a non-default value for the order parameter unless you really know
// what you are doing and have thought about it very hard. The cost of seq_cst
// is usually not high enough to justify the risk.
Modified: trunk/Source/WTF/wtf/Lock.cpp (188716 => 188717)
--- trunk/Source/WTF/wtf/Lock.cpp 2015-08-20 23:06:13 UTC (rev 188716)
+++ trunk/Source/WTF/wtf/Lock.cpp 2015-08-21 00:00:29 UTC (rev 188717)
@@ -36,7 +36,7 @@
static const bool verbose = false;
-void LockBase::lockSlow()
+void Lock::lockSlow()
{
unsigned spinCount = 0;
@@ -74,7 +74,7 @@
}
}
-void LockBase::unlockSlow()
+void Lock::unlockSlow()
{
// We could get here because the weak CAS in unlock() failed spuriously, or because there is
// someone parked. So, we need a CAS loop: even if right now the lock is just held, it could
Modified: trunk/Source/WTF/wtf/Lock.h (188716 => 188717)
--- trunk/Source/WTF/wtf/Lock.h 2015-08-20 23:06:13 UTC (rev 188716)
+++ trunk/Source/WTF/wtf/Lock.h 2015-08-21 00:00:29 UTC (rev 188717)
@@ -45,7 +45,7 @@
// This is a struct without a constructor or destructor so that it can be statically initialized.
// Use Lock in instance variables.
-struct LockBase {
+struct Lock {
void lock()
{
if (LIKELY(m_byte.compareExchangeWeak(0, isHeldBit, std::memory_order_acquire))) {
@@ -108,20 +108,13 @@
return !m_byte.load();
}
- Atomic<uint8_t> m_byte;
+ Atomic<uint8_t> m_byte { 0 };
};
-class Lock : public LockBase {
- WTF_MAKE_NONCOPYABLE(Lock);
-public:
- Lock()
- {
- m_byte.store(0, std::memory_order_relaxed);
- }
-};
+typedef Locker<Lock> LockHolder;
-typedef LockBase StaticLock;
-typedef Locker<LockBase> LockHolder;
+// FIXME: Once all clients have been moved from StaticLock to Lock we can get rid of this typedef.
+typedef Lock StaticLock;
} // namespace WTF
Modified: trunk/Source/WTF/wtf/WordLock.h (188716 => 188717)
--- trunk/Source/WTF/wtf/WordLock.h 2015-08-20 23:06:13 UTC (rev 188716)
+++ trunk/Source/WTF/wtf/WordLock.h 2015-08-21 00:00:29 UTC (rev 188717)
@@ -45,10 +45,7 @@
class WordLock {
WTF_MAKE_NONCOPYABLE(WordLock);
public:
- WordLock()
- {
- m_word.store(0, std::memory_order_relaxed);
- }
+ CONSTEXPR WordLock() = default;
void lock()
{
@@ -96,7 +93,7 @@
return !m_word.load();
}
- Atomic<uintptr_t> m_word;
+ Atomic<uintptr_t> m_word { 0 };
};
typedef Locker<WordLock> WordLockHolder;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes