Skip to content
Closed
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
4 changes: 4 additions & 0 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ GlobalHandler &GlobalHandler::instance() {
return *RTGlobalObjHandler;
}

bool GlobalHandler::isInstanceAlive() {
return GlobalHandler::getInstancePtr();
}

template <typename T, typename... Types>
T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types &&...Args) {
const LockGuard Lock{IWL.Lock};
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class GlobalHandler {
/// `__attribute__((destructor))` is called).
static GlobalHandler &instance();

/// \return true if the instance has not been deallocated yet.
static bool isInstanceAlive();

GlobalHandler(const GlobalHandler &) = delete;
GlobalHandler(GlobalHandler &&) = delete;
GlobalHandler &operator=(const GlobalHandler &) = delete;
Expand Down
5 changes: 2 additions & 3 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3927,9 +3927,8 @@ extern "C" void __sycl_register_lib(sycl_device_binaries desc) {
// Executed as a part of current module's (.exe, .dll) static initialization
extern "C" void __sycl_unregister_lib(sycl_device_binaries desc) {
// Partial cleanup is not necessary at shutdown
#ifndef _WIN32
if (!sycl::detail::GlobalHandler::instance().isOkToDefer())
if (!sycl::detail::GlobalHandler::isInstanceAlive() ||
!sycl::detail::GlobalHandler::instance().isOkToDefer())
return;
sycl::detail::ProgramManager::getInstance().removeImages(desc);
#endif
}