Files
compute-runtime/shared/source/memory_manager/deferred_deleter.h
HeFan2017 2ea734491a Deferred deletion of allocations in main thread
Add a clearQueueTillFirstFailure interface to DeferredDeleter, which
iterates the queue from the front and delete the allocations in the
queue till a failure. It is called by defer deletion of allocations
occupied by mutliple contexts to unlock the execution in main thread

Related-To: NEO-7532

Signed-off-by: HeFan2017 <fan.f.he@intel.com>
2023-01-13 09:20:35 +01:00

56 lines
1.3 KiB
C++

/*
* Copyright (C) 2018-2023 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);
MOCKABLE_VIRTUAL void clearQueueTillFirstFailure();
protected:
void stop();
void safeStop();
void ensureThread();
MOCKABLE_VIRTUAL void clearQueue(bool breakOnFailure);
MOCKABLE_VIRTUAL bool areElementsReleased();
MOCKABLE_VIRTUAL bool shouldStop();
static void *run(void *);
std::atomic<bool> doWorkInBackground;
std::atomic<int> elementsToRelease;
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