DrmGemCloseWorker now works on BufferObject instead of DrmAllocation.

Change-Id: I490edfc7532081eb31f700be70781c276dbc2916
This commit is contained in:
Mrozek, Michal 2018-05-11 08:10:18 +02:00
parent bab9ad6cda
commit 2c896b64b4
3 changed files with 13 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (c) 2017 - 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -54,7 +54,7 @@ DrmGemCloseWorker::~DrmGemCloseWorker() {
closeThread();
}
void DrmGemCloseWorker::push(DrmAllocation *bo) {
void DrmGemCloseWorker::push(BufferObject *bo) {
std::unique_lock<std::mutex> lock(closeWorkerMutex);
workCount++;
queue.push(bo);
@ -74,19 +74,15 @@ bool DrmGemCloseWorker::isEmpty() {
return workCount.load() == 0;
}
inline void DrmGemCloseWorker::close(DrmAllocation *alloc) {
auto bo = alloc->getBO();
inline void DrmGemCloseWorker::close(BufferObject *bo) {
bo->wait(-1);
memoryManager.unreference(bo);
workCount--;
delete alloc;
}
void DrmGemCloseWorker::worker() {
DrmAllocation *workItem = nullptr;
std::queue<DrmAllocation *> localQueue;
BufferObject *workItem = nullptr;
std::queue<BufferObject *> localQueue;
std::unique_lock<std::mutex> lock(closeWorkerMutex);
lock.unlock();

View File

@ -32,7 +32,7 @@
namespace OCLRT {
class DrmMemoryManager;
class DrmAllocation;
class BufferObject;
enum gemCloseWorkerMode {
gemCloseWorkerInactive,
@ -47,20 +47,20 @@ class DrmGemCloseWorker {
DrmGemCloseWorker(const DrmGemCloseWorker &) = delete;
DrmGemCloseWorker &operator=(const DrmGemCloseWorker &) = delete;
void push(DrmAllocation *allocation);
void push(BufferObject *allocation);
void close(bool blocking);
bool isEmpty();
protected:
void close(DrmAllocation *workItem);
void close(BufferObject *workItem);
void closeThread();
void worker();
bool active;
std::thread *thread;
std::queue<DrmAllocation *> queue;
std::queue<BufferObject *> queue;
std::atomic<uint32_t> workCount;
DrmMemoryManager &memoryManager;

View File

@ -112,9 +112,8 @@ TEST_F(DrmGemCloseWorkerTests, gemClose) {
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObjectWrapper(this->drmMock, 1);
auto alloc = new DrmAllocationWrapper(bo);
worker->push(alloc);
worker->push(bo);
delete worker;
}
@ -124,9 +123,8 @@ TEST_F(DrmGemCloseWorkerTests, gemCloseExit) {
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObjectWrapper(this->drmMock, 1);
auto alloc = new DrmAllocationWrapper(bo);
worker->push(alloc);
worker->push(bo);
//wait for worker to complete or deadCnt drops
while (!worker->isEmpty() && (deadCnt-- > 0))
@ -145,9 +143,8 @@ TEST_F(DrmGemCloseWorkerTests, close) {
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObjectWrapper(this->drmMock, 1);
auto alloc = new DrmAllocationWrapper(bo);
worker->push(alloc);
worker->push(bo);
worker->close(false);
//wait for worker to complete or deadCnt drops
@ -164,10 +161,9 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObjectWrapper(this->drmMock, 1);
auto alloc = new DrmAllocationWrapper(bo);
bo->reference();
worker->push(alloc);
worker->push(bo);
auto r = mm->unreference(bo, true);
EXPECT_EQ(1u, r);