1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
/*
* 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
|