Title: [224597] trunk
- Revision
- 224597
- Author
- [email protected]
- Date
- 2017-11-08 14:50:59 -0800 (Wed, 08 Nov 2017)
Log Message
[ios-simulator] API test WebKit.BundleParameters is a flaky failure
https://bugs.webkit.org/show_bug.cgi?id=178363
<rdar://problem/35043144>
Reviewed by Brent Fulgham.
* wtf/RefCounter.h:
(WTF::RefCounter<T>::Count::deref):
(WTF::RefCounter<T>::Count::refCounterWasDeleted):
(WTF::RefCounter<T>::~RefCounter):
If a RefCounter::Count is deref()'d and drops its RefCounter's value to
zero, and the RefCounter is deleted in that valueDidChangeCallback, it
will delete the Counter that is in the middle of deref(). Keep track
of whether we're inside the callback and defer the deletion until
the end of deref().
* TestWebKitAPI/Tests/WTF/RefCounter.cpp:
(TestWebKitAPI::TEST):
Add a test.
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (224596 => 224597)
--- trunk/Source/WTF/ChangeLog 2017-11-08 22:01:15 UTC (rev 224596)
+++ trunk/Source/WTF/ChangeLog 2017-11-08 22:50:59 UTC (rev 224597)
@@ -1,3 +1,21 @@
+2017-11-08 Tim Horton <[email protected]>
+
+ [ios-simulator] API test WebKit.BundleParameters is a flaky failure
+ https://bugs.webkit.org/show_bug.cgi?id=178363
+ <rdar://problem/35043144>
+
+ Reviewed by Brent Fulgham.
+
+ * wtf/RefCounter.h:
+ (WTF::RefCounter<T>::Count::deref):
+ (WTF::RefCounter<T>::Count::refCounterWasDeleted):
+ (WTF::RefCounter<T>::~RefCounter):
+ If a RefCounter::Count is deref()'d and drops its RefCounter's value to
+ zero, and the RefCounter is deleted in that valueDidChangeCallback, it
+ will delete the Counter that is in the middle of deref(). Keep track
+ of whether we're inside the callback and defer the deletion until
+ the end of deref().
+
2017-11-07 Maciej Stachowiak <[email protected]>
Get rid of unsightly hex numbers from unified build object files
Modified: trunk/Source/WTF/wtf/RefCounter.h (224596 => 224597)
--- trunk/Source/WTF/wtf/RefCounter.h 2017-11-08 22:01:15 UTC (rev 224596)
+++ trunk/Source/WTF/wtf/RefCounter.h 2017-11-08 22:50:59 UTC (rev 224597)
@@ -29,6 +29,7 @@
#include <wtf/Function.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
+#include <wtf/SetForScope.h>
namespace WTF {
@@ -44,6 +45,8 @@
void ref();
void deref();
+ void refCounterWasDeleted();
+
private:
friend class RefCounter;
@@ -55,6 +58,7 @@
RefCounter* m_refCounter;
size_t m_value;
+ bool m_inValueDidChange { false };
};
public:
@@ -93,8 +97,11 @@
ASSERT(m_value);
--m_value;
- if (m_refCounter && m_refCounter->m_valueDidChange)
+
+ if (m_refCounter && m_refCounter->m_valueDidChange) {
+ SetForScope<bool> inCallback(m_inValueDidChange, true);
m_refCounter->m_valueDidChange(RefCounterEvent::Decrement);
+ }
// The Count object is kept alive so long as either the RefCounter that created it remains
// allocated, or so long as its reference count is non-zero.
@@ -105,6 +112,23 @@
}
template<typename T>
+inline void RefCounter<T>::Count::refCounterWasDeleted()
+{
+ // The Count object is kept alive so long as either the RefCounter that created it remains
+ // allocated, or so long as its reference count is non-zero.
+ // If the reference count of the Count is already zero then delete it now, otherwise
+ // clear its m_refCounter pointer.
+
+ m_refCounter = nullptr;
+
+ if (m_inValueDidChange)
+ return;
+
+ if (!m_value)
+ delete this;
+}
+
+template<typename T>
inline RefCounter<T>::RefCounter(ValueChangeFunction&& valueDidChange)
: m_valueDidChange(WTFMove(valueDidChange))
, m_count(new Count(*this))
@@ -114,14 +138,8 @@
template<typename T>
inline RefCounter<T>::~RefCounter()
{
- // The Count object is kept alive so long as either the RefCounter that created it remains
- // allocated, or so long as its reference count is non-zero.
- // If the reference count of the Count is already zero then delete it now, otherwise
- // clear its m_refCounter pointer.
- if (m_count->m_value)
- m_count->m_refCounter = nullptr;
- else
- delete m_count;
+ m_count->refCounterWasDeleted();
+
}
} // namespace WTF
Modified: trunk/Tools/ChangeLog (224596 => 224597)
--- trunk/Tools/ChangeLog 2017-11-08 22:01:15 UTC (rev 224596)
+++ trunk/Tools/ChangeLog 2017-11-08 22:50:59 UTC (rev 224597)
@@ -1,3 +1,15 @@
+2017-11-08 Tim Horton <[email protected]>
+
+ [ios-simulator] API test WebKit.BundleParameters is a flaky failure
+ https://bugs.webkit.org/show_bug.cgi?id=178363
+ <rdar://problem/35043144>
+
+ Reviewed by Brent Fulgham.
+
+ * TestWebKitAPI/Tests/WTF/RefCounter.cpp:
+ (TestWebKitAPI::TEST):
+ Add a test.
+
2017-11-08 Wenson Hsieh <[email protected]>
[Attachment Support] Implement delegate hooks for attachment element insertion and removal
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp (224596 => 224597)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp 2017-11-08 22:01:15 UTC (rev 224596)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp 2017-11-08 22:50:59 UTC (rev 224597)
@@ -167,4 +167,19 @@
// ... not a lot to test here! - we can at least ensure this code path is run & we don't crash!
}
+TEST(WTF, RefCounterDeleteCounterWithOutstandingTokens)
+{
+ {
+ std::unique_ptr<TestCounter> counter = std::make_unique<TestCounter>([&](RefCounterEvent event) {
+ if (!counter->value())
+ counter = nullptr;
+ });
+
+ TokenType incTo1 = counter->count();
+ EXPECT_EQ(1UL, counter->value());
+ incTo1 = nullptr;
+ EXPECT_EQ(nullptr, counter.get());
+ }
+}
+
} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes