mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-31 20:13:04 +08:00
Cleaner thread will run every 15ms instead of 2s. Allocations will be held for at least 10s. If deferred deleter has elements to release, will skip cleaning cache. Will clean only 1 allocation per cache, per cleaning run. Related-To: NEO-6893 Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
/*
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include "shared/source/utilities/idlist.h"
|
|
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
|
|
namespace NEO {
|
|
class DeferrableDeletion;
|
|
class Thread;
|
|
class DeferredDeleter {
|
|
public:
|
|
DeferredDeleter();
|
|
virtual ~DeferredDeleter();
|
|
|
|
DeferredDeleter(const DeferredDeleter &) = delete;
|
|
DeferredDeleter &operator=(const DeferredDeleter &) = delete;
|
|
|
|
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> 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;
|
|
};
|
|
} // namespace NEO
|