mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
Join thread in DllMain (which we are not aware of) can result in hang occurring in DeferredDeleter, if the library is freed before FreeLibraryAndExitThread call from within the worker thread, the thread gets stuck, thus the main thread is stuck on worker->join(). Related-To: NEO-14121 Signed-off-by: Oskar Hubert Weber <oskar.hubert.weber@intel.com>
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
/*
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
|
#include "shared/source/utilities/idlist.h"
|
|
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
|
|
namespace NEO {
|
|
class DeferrableDeletion;
|
|
class Thread;
|
|
class DeferredDeleter : NEO::NonCopyableAndNonMovableClass {
|
|
public:
|
|
DeferredDeleter();
|
|
virtual ~DeferredDeleter();
|
|
|
|
MOCKABLE_VIRTUAL void deferDeletion(DeferrableDeletion *deletion);
|
|
|
|
MOCKABLE_VIRTUAL void addClient();
|
|
|
|
MOCKABLE_VIRTUAL void removeClient();
|
|
|
|
MOCKABLE_VIRTUAL void drain(bool blocking, bool hostptrsOnly);
|
|
|
|
MOCKABLE_VIRTUAL bool areElementsReleased(bool hostptrsOnly);
|
|
|
|
protected:
|
|
void stop();
|
|
void safeStop();
|
|
void ensureThread();
|
|
MOCKABLE_VIRTUAL void clearQueue(bool hostptrsOnly);
|
|
MOCKABLE_VIRTUAL bool shouldStop();
|
|
|
|
static void *run(void *);
|
|
|
|
std::atomic<bool> exitedMainLoop = false;
|
|
std::atomic<bool> doWorkInBackground = false;
|
|
std::atomic<int> elementsToRelease = 0;
|
|
std::atomic<int> hostptrsToRelease = 0;
|
|
std::unique_ptr<Thread> worker;
|
|
int32_t numClients = 0;
|
|
IDList<DeferrableDeletion, true> queue;
|
|
std::mutex queueMutex;
|
|
std::mutex threadMutex;
|
|
std::condition_variable condition;
|
|
};
|
|
|
|
static_assert(NEO::NonCopyableAndNonMovable<DeferredDeleter>);
|
|
|
|
} // namespace NEO
|