Allow WeakRef with incomplete types
Previously using WeakRef required that the full type definition was
included. This was due to the GetWeakRef() methods being a friend of the
WeakRef class so they could call the private constructor directly.
By introducing a static WeakRef<T>::Get() function which calls the
constructor and pointing the GetWeakRef calls at it we break the need
for the friend association, which in turn allows WeakRef to be used with
only a forward declaration of the type while still allowing GetWeakRef
to be called as before.
Bug: 416088623
Change-Id: I68f7d08eb1d75cff3dbce9c21459d8e6bc2b2a44
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/242276
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/common/WeakRef.h b/src/dawn/common/WeakRef.h
index c5adc1b..5322b59 100644
--- a/src/dawn/common/WeakRef.h
+++ b/src/dawn/common/WeakRef.h
@@ -38,23 +38,26 @@
template <typename T>
class WeakRef;
+// GetWeakRef is a less verbose method of calling of WeakRef<typename>::Get(obj);
template <
typename T,
typename = typename std::enable_if<std::is_base_of_v<detail::WeakRefSupportBase, T>>::type>
WeakRef<T> GetWeakRef(T* obj) {
- return WeakRef<T>(obj);
+ return WeakRef<T>::Get(obj);
}
template <
typename T,
typename = typename std::enable_if<std::is_base_of_v<detail::WeakRefSupportBase, T>>::type>
WeakRef<T> GetWeakRef(const Ref<T>& obj) {
- return GetWeakRef(obj.Get());
+ return WeakRef<T>::Get(obj.Get());
}
template <typename T>
class WeakRef {
public:
+ static WeakRef<T> Get(T* obj) { return WeakRef<T>(obj); }
+
WeakRef() {}
// Constructors from nullptr.
@@ -105,9 +108,6 @@
return nullptr;
}
- friend WeakRef GetWeakRef<>(T* obj);
- friend WeakRef GetWeakRef<>(const Ref<T>& obj);
-
private:
// Friend is needed so that we can access the data ref in conversions.
template <typename U>
diff --git a/src/dawn/native/EventManager.h b/src/dawn/native/EventManager.h
index 90ac919..3b79db8 100644
--- a/src/dawn/native/EventManager.h
+++ b/src/dawn/native/EventManager.h
@@ -43,7 +43,6 @@
#include "dawn/native/Error.h"
#include "dawn/native/Forward.h"
#include "dawn/native/IntegerTypes.h"
-#include "dawn/native/Queue.h"
#include "dawn/native/SystemEvent.h"
#include "dawn/native/WaitListEvent.h"
#include "partition_alloc/pointers/raw_ptr.h"
@@ -51,6 +50,7 @@
namespace dawn::native {
struct InstanceDescriptor;
+class QueueBase;
// Subcomponent of the Instance which tracks callback events for the Future-based callback
// entrypoints. All events from this instance (regardless of whether from an adapter, device, queue,