mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-26 15:03:02 +08:00
refactor: simplify logic in drm gem close worker
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
adc51c1b47
commit
7a4e3f2d09
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -66,16 +66,23 @@ inline void DrmGemCloseWorker::close(BufferObject *bo) {
|
||||
workCount--;
|
||||
}
|
||||
|
||||
inline void DrmGemCloseWorker::processQueue(std::queue<BufferObject *> &inputQueue) {
|
||||
BufferObject *workItem = nullptr;
|
||||
while (!inputQueue.empty()) {
|
||||
workItem = inputQueue.front();
|
||||
inputQueue.pop();
|
||||
close(workItem);
|
||||
}
|
||||
}
|
||||
|
||||
void *DrmGemCloseWorker::worker(void *arg) {
|
||||
DrmGemCloseWorker *self = reinterpret_cast<DrmGemCloseWorker *>(arg);
|
||||
BufferObject *workItem = nullptr;
|
||||
std::queue<BufferObject *> localQueue;
|
||||
std::unique_lock<std::mutex> lock(self->closeWorkerMutex);
|
||||
lock.unlock();
|
||||
|
||||
while (self->active) {
|
||||
lock.lock();
|
||||
workItem = nullptr;
|
||||
|
||||
while (self->queue.empty() && self->active) {
|
||||
self->condition.wait(lock);
|
||||
@@ -86,19 +93,11 @@ void *DrmGemCloseWorker::worker(void *arg) {
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
while (!localQueue.empty()) {
|
||||
workItem = localQueue.front();
|
||||
localQueue.pop();
|
||||
self->close(workItem);
|
||||
}
|
||||
self->processQueue(localQueue);
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
while (!self->queue.empty()) {
|
||||
workItem = self->queue.front();
|
||||
self->queue.pop();
|
||||
self->close(workItem);
|
||||
}
|
||||
self->processQueue(self->queue);
|
||||
|
||||
lock.unlock();
|
||||
self->workerDone.store(true);
|
||||
|
||||
@@ -40,6 +40,7 @@ class DrmGemCloseWorker {
|
||||
protected:
|
||||
void close(BufferObject *workItem);
|
||||
void closeThread();
|
||||
void processQueue(std::queue<BufferObject *> &inputQueue);
|
||||
static void *worker(void *arg);
|
||||
std::atomic<bool> active{true};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user