Skip to content

Commit 7a4e3f2

Browse files
refactor: simplify logic in drm gem close worker
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent adc51c1 commit 7a4e3f2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

shared/source/os_interface/linux/drm_gem_close_worker.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -66,16 +66,23 @@ inline void DrmGemCloseWorker::close(BufferObject *bo) {
6666
workCount--;
6767
}
6868

69+
inline void DrmGemCloseWorker::processQueue(std::queue<BufferObject *> &inputQueue) {
70+
BufferObject *workItem = nullptr;
71+
while (!inputQueue.empty()) {
72+
workItem = inputQueue.front();
73+
inputQueue.pop();
74+
close(workItem);
75+
}
76+
}
77+
6978
void *DrmGemCloseWorker::worker(void *arg) {
7079
DrmGemCloseWorker *self = reinterpret_cast<DrmGemCloseWorker *>(arg);
71-
BufferObject *workItem = nullptr;
7280
std::queue<BufferObject *> localQueue;
7381
std::unique_lock<std::mutex> lock(self->closeWorkerMutex);
7482
lock.unlock();
7583

7684
while (self->active) {
7785
lock.lock();
78-
workItem = nullptr;
7986

8087
while (self->queue.empty() && self->active) {
8188
self->condition.wait(lock);
@@ -86,19 +93,11 @@ void *DrmGemCloseWorker::worker(void *arg) {
8693
}
8794

8895
lock.unlock();
89-
while (!localQueue.empty()) {
90-
workItem = localQueue.front();
91-
localQueue.pop();
92-
self->close(workItem);
93-
}
96+
self->processQueue(localQueue);
9497
}
9598

9699
lock.lock();
97-
while (!self->queue.empty()) {
98-
workItem = self->queue.front();
99-
self->queue.pop();
100-
self->close(workItem);
101-
}
100+
self->processQueue(self->queue);
102101

103102
lock.unlock();
104103
self->workerDone.store(true);

shared/source/os_interface/linux/drm_gem_close_worker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class DrmGemCloseWorker {
4040
protected:
4141
void close(BufferObject *workItem);
4242
void closeThread();
43+
void processQueue(std::queue<BufferObject *> &inputQueue);
4344
static void *worker(void *arg);
4445
std::atomic<bool> active{true};
4546

0 commit comments

Comments
 (0)