2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
|
|
#include <condition_variable>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <cstdint>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <map>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <mutex>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <queue>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <set>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
class DrmMemoryManager;
|
2018-05-11 14:10:18 +08:00
|
|
|
class BufferObject;
|
2018-05-22 23:23:39 +08:00
|
|
|
class Thread;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
enum gemCloseWorkerMode {
|
|
|
|
gemCloseWorkerInactive,
|
2018-05-10 16:16:22 +08:00
|
|
|
gemCloseWorkerActive
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class DrmGemCloseWorker {
|
|
|
|
public:
|
|
|
|
DrmGemCloseWorker(DrmMemoryManager &memoryManager);
|
|
|
|
~DrmGemCloseWorker();
|
|
|
|
|
|
|
|
DrmGemCloseWorker(const DrmGemCloseWorker &) = delete;
|
|
|
|
DrmGemCloseWorker &operator=(const DrmGemCloseWorker &) = delete;
|
|
|
|
|
2018-05-11 14:10:18 +08:00
|
|
|
void push(BufferObject *allocation);
|
2017-12-21 07:45:38 +08:00
|
|
|
void close(bool blocking);
|
|
|
|
|
|
|
|
bool isEmpty();
|
|
|
|
|
2018-05-10 16:16:22 +08:00
|
|
|
protected:
|
2018-05-11 14:10:18 +08:00
|
|
|
void close(BufferObject *workItem);
|
2017-12-21 07:45:38 +08:00
|
|
|
void closeThread();
|
2018-05-22 23:23:39 +08:00
|
|
|
static void *worker(void *arg);
|
|
|
|
bool active = true;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-05-22 23:23:39 +08:00
|
|
|
std::unique_ptr<Thread> thread;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-05-11 14:10:18 +08:00
|
|
|
std::queue<BufferObject *> queue;
|
2018-05-22 23:23:39 +08:00
|
|
|
std::atomic<uint32_t> workCount{0};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
DrmMemoryManager &memoryManager;
|
|
|
|
|
|
|
|
std::mutex closeWorkerMutex;
|
|
|
|
std::condition_variable condition;
|
2018-05-22 23:23:39 +08:00
|
|
|
std::atomic<bool> workerDone{false};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2018-06-13 03:54:39 +08:00
|
|
|
} // namespace OCLRT
|