2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/utilities/idlist.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <atomic>
|
|
|
|
|
#include <condition_variable>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
class DeferrableDeletion;
|
2018-05-22 17:23:39 +02:00
|
|
|
class Thread;
|
2017-12-21 00:45:38 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void stop();
|
2018-03-19 11:54:50 +01:00
|
|
|
void safeStop();
|
2017-12-21 00:45:38 +01:00
|
|
|
void ensureThread();
|
|
|
|
|
MOCKABLE_VIRTUAL void clearQueue();
|
|
|
|
|
MOCKABLE_VIRTUAL bool areElementsReleased();
|
|
|
|
|
MOCKABLE_VIRTUAL bool shouldStop();
|
|
|
|
|
|
2018-05-22 17:23:39 +02:00
|
|
|
static void *run(void *);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
std::atomic<bool> doWorkInBackground;
|
|
|
|
|
std::atomic<int> elementsToRelease;
|
2018-05-22 17:23:39 +02:00
|
|
|
std::unique_ptr<Thread> worker;
|
2017-12-21 00:45:38 +01:00
|
|
|
int32_t numClients = 0;
|
|
|
|
|
IDList<DeferrableDeletion, true> queue;
|
|
|
|
|
std::mutex queueMutex;
|
|
|
|
|
std::mutex threadMutex;
|
|
|
|
|
std::condition_variable condition;
|
|
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|