Title: [248386] trunk/Source/WTF
- Revision
- 248386
- Author
- [email protected]
- Date
- 2019-08-07 13:35:11 -0700 (Wed, 07 Aug 2019)
Log Message
Tighten WeakPtr threading assertions for GC threads
https://bugs.webkit.org/show_bug.cgi?id=200451
Reviewed by Youenn Fablet.
Make sure our GC threads do not dereference WeakPtr for main thread
objects by tightening our threading assertions in WeakPtr. They are
still allowed to call WeakPtr::get() for now though.
* wtf/WeakPtr.h:
(WTF::WeakPtrImpl::get):
(WTF::WeakPtrImpl::wasConstructedOnMainThread const):
(WTF::WeakPtr::get const):
(WTF::WeakPtr::operator-> const):
(WTF::WeakPtr::operator* const):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (248385 => 248386)
--- trunk/Source/WTF/ChangeLog 2019-08-07 20:32:30 UTC (rev 248385)
+++ trunk/Source/WTF/ChangeLog 2019-08-07 20:35:11 UTC (rev 248386)
@@ -1,3 +1,21 @@
+2019-08-07 Chris Dumez <[email protected]>
+
+ Tighten WeakPtr threading assertions for GC threads
+ https://bugs.webkit.org/show_bug.cgi?id=200451
+
+ Reviewed by Youenn Fablet.
+
+ Make sure our GC threads do not dereference WeakPtr for main thread
+ objects by tightening our threading assertions in WeakPtr. They are
+ still allowed to call WeakPtr::get() for now though.
+
+ * wtf/WeakPtr.h:
+ (WTF::WeakPtrImpl::get):
+ (WTF::WeakPtrImpl::wasConstructedOnMainThread const):
+ (WTF::WeakPtr::get const):
+ (WTF::WeakPtr::operator-> const):
+ (WTF::WeakPtr::operator* const):
+
2019-08-06 Jiewen Tan <[email protected]>
Unreviewed, a build fix after r248308
Modified: trunk/Source/WTF/wtf/WeakPtr.h (248385 => 248386)
--- trunk/Source/WTF/wtf/WeakPtr.h 2019-08-07 20:32:30 UTC (rev 248385)
+++ trunk/Source/WTF/wtf/WeakPtr.h 2019-08-07 20:35:11 UTC (rev 248386)
@@ -62,8 +62,6 @@
template<typename T> typename T::WeakValueType* get()
{
- // FIXME: We need to fix thread-safety bugs in WebCore and stop being more permissive for GC threads here.
- ASSERT(Thread::mayBeGCThread() || m_wasConstructedOnMainThread == isMainThread());
return static_cast<typename T::WeakValueType*>(m_ptr);
}
@@ -70,6 +68,10 @@
explicit operator bool() const { return m_ptr; }
void clear() { m_ptr = nullptr; }
+#if !ASSERT_DISABLED
+ bool wasConstructedOnMainThread() const { return m_wasConstructedOnMainThread; }
+#endif
+
private:
template<typename T> explicit WeakPtrImpl(T* ptr)
: m_ptr(static_cast<typename T::WeakValueType*>(ptr))
@@ -95,7 +97,13 @@
template<typename U> WeakPtr(const WeakPtr<U>&);
template<typename U> WeakPtr(WeakPtr<U>&&);
- T* get() const { return m_impl ? static_cast<T*>(m_impl->get<T>()) : nullptr; }
+ T* get() const
+ {
+ // FIXME: Our GC threads currently need to get opaque pointers from WeakPtrs and have to be special-cased.
+ ASSERT(!m_impl || Thread::mayBeGCThread() || m_impl->wasConstructedOnMainThread() == isMainThread());
+ return m_impl ? static_cast<T*>(m_impl->get<T>()) : nullptr;
+ }
+
explicit operator bool() const { return m_impl && *m_impl; }
WeakPtr& operator=(std::nullptr_t) { m_impl = nullptr; return *this; }
@@ -102,9 +110,18 @@
template<typename U> WeakPtr& operator=(const WeakPtr<U>&);
template<typename U> WeakPtr& operator=(WeakPtr<U>&&);
- T* operator->() const { return get(); }
- T& operator*() const { return *get(); }
+ T* operator->() const
+ {
+ ASSERT(!m_impl || m_impl->wasConstructedOnMainThread() == isMainThread());
+ return get();
+ }
+ T& operator*() const
+ {
+ ASSERT(!m_impl || m_impl->wasConstructedOnMainThread() == isMainThread());
+ return *get();
+ }
+
void clear() { m_impl = nullptr; }
private:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes