Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sycl/include/sycl/ext/oneapi/weak_object_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ template <typename SYCLObjT> class weak_object_base {
weak_object_base(const weak_object_base &Other) noexcept = default;
weak_object_base(weak_object_base &&Other) noexcept = default;

weak_object_base &operator=(const weak_object_base &Other) noexcept = default;
weak_object_base &operator=(weak_object_base &&Other) noexcept = default;

void reset() noexcept { MObjWeakPtr.reset(); }
void swap(weak_object_base &Other) noexcept {
MObjWeakPtr.swap(Other.MObjWeakPtr);
Expand Down
43 changes: 43 additions & 0 deletions sycl/unittests/Extensions/WeakObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,39 @@ template <typename SyclObjT> struct WeakObjectCheckOwnerLessMap {
}
};

template <typename SyclObjT> struct WeakObjectCheckCopy {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj{Obj};

sycl::ext::oneapi::weak_object<SyclObjT> WeakObjCopyCtor{WeakObj};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjCopyAssign = WeakObj;

EXPECT_FALSE(WeakObjCopyCtor.expired());
EXPECT_FALSE(WeakObjCopyAssign.expired());

EXPECT_TRUE(WeakObjCopyCtor.lock() == Obj);
EXPECT_TRUE(WeakObjCopyAssign.lock() == Obj);
}
};

template <typename SyclObjT> struct WeakObjectCheckMove {
void operator()(SyclObjT Obj) {
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj1{Obj};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObj2{Obj};

sycl::ext::oneapi::weak_object<SyclObjT> WeakObjMoveCtor{
std::move(WeakObj1)};
sycl::ext::oneapi::weak_object<SyclObjT> WeakObjMoveAssign =
std::move(WeakObj2);

EXPECT_FALSE(WeakObjMoveCtor.expired());
EXPECT_FALSE(WeakObjMoveAssign.expired());

EXPECT_TRUE(WeakObjMoveCtor.lock() == Obj);
EXPECT_TRUE(WeakObjMoveAssign.lock() == Obj);
}
};

template <template <typename> typename CallableT>
void runTest(sycl::unittest::PiMock &Mock) {
sycl::platform Plt = Mock.getPlatform();
Expand Down Expand Up @@ -385,3 +418,13 @@ TEST(WeakObjectTest, WeakObjectOwnerLessMap) {
sycl::unittest::PiMock Mock;
runTestMulti<WeakObjectCheckOwnerLessMap>(Mock);
}

TEST(WeakObjectTest, WeakObjectCopy) {
sycl::unittest::PiMock Mock;
runTest<WeakObjectCheckCopy>(Mock);
}

TEST(WeakObjectTest, WeakObjectMove) {
sycl::unittest::PiMock Mock;
runTest<WeakObjectCheckMove>(Mock);
}