DrmGemCloseWorker now works on BufferObject instead of DrmAllocation.
Change-Id: I490edfc7532081eb31f700be70781c276dbc2916
This commit is contained in:
parent
bab9ad6cda
commit
2c896b64b4
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -54,7 +54,7 @@ DrmGemCloseWorker::~DrmGemCloseWorker() {
|
||||||
closeThread();
|
closeThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrmGemCloseWorker::push(DrmAllocation *bo) {
|
void DrmGemCloseWorker::push(BufferObject *bo) {
|
||||||
std::unique_lock<std::mutex> lock(closeWorkerMutex);
|
std::unique_lock<std::mutex> lock(closeWorkerMutex);
|
||||||
workCount++;
|
workCount++;
|
||||||
queue.push(bo);
|
queue.push(bo);
|
||||||
|
@ -74,19 +74,15 @@ bool DrmGemCloseWorker::isEmpty() {
|
||||||
return workCount.load() == 0;
|
return workCount.load() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DrmGemCloseWorker::close(DrmAllocation *alloc) {
|
inline void DrmGemCloseWorker::close(BufferObject *bo) {
|
||||||
auto bo = alloc->getBO();
|
|
||||||
|
|
||||||
bo->wait(-1);
|
bo->wait(-1);
|
||||||
memoryManager.unreference(bo);
|
memoryManager.unreference(bo);
|
||||||
workCount--;
|
workCount--;
|
||||||
|
|
||||||
delete alloc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrmGemCloseWorker::worker() {
|
void DrmGemCloseWorker::worker() {
|
||||||
DrmAllocation *workItem = nullptr;
|
BufferObject *workItem = nullptr;
|
||||||
std::queue<DrmAllocation *> localQueue;
|
std::queue<BufferObject *> localQueue;
|
||||||
std::unique_lock<std::mutex> lock(closeWorkerMutex);
|
std::unique_lock<std::mutex> lock(closeWorkerMutex);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
namespace OCLRT {
|
namespace OCLRT {
|
||||||
class DrmMemoryManager;
|
class DrmMemoryManager;
|
||||||
class DrmAllocation;
|
class BufferObject;
|
||||||
|
|
||||||
enum gemCloseWorkerMode {
|
enum gemCloseWorkerMode {
|
||||||
gemCloseWorkerInactive,
|
gemCloseWorkerInactive,
|
||||||
|
@ -47,20 +47,20 @@ class DrmGemCloseWorker {
|
||||||
DrmGemCloseWorker(const DrmGemCloseWorker &) = delete;
|
DrmGemCloseWorker(const DrmGemCloseWorker &) = delete;
|
||||||
DrmGemCloseWorker &operator=(const DrmGemCloseWorker &) = delete;
|
DrmGemCloseWorker &operator=(const DrmGemCloseWorker &) = delete;
|
||||||
|
|
||||||
void push(DrmAllocation *allocation);
|
void push(BufferObject *allocation);
|
||||||
void close(bool blocking);
|
void close(bool blocking);
|
||||||
|
|
||||||
bool isEmpty();
|
bool isEmpty();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void close(DrmAllocation *workItem);
|
void close(BufferObject *workItem);
|
||||||
void closeThread();
|
void closeThread();
|
||||||
void worker();
|
void worker();
|
||||||
bool active;
|
bool active;
|
||||||
|
|
||||||
std::thread *thread;
|
std::thread *thread;
|
||||||
|
|
||||||
std::queue<DrmAllocation *> queue;
|
std::queue<BufferObject *> queue;
|
||||||
std::atomic<uint32_t> workCount;
|
std::atomic<uint32_t> workCount;
|
||||||
|
|
||||||
DrmMemoryManager &memoryManager;
|
DrmMemoryManager &memoryManager;
|
||||||
|
|
|
@ -112,9 +112,8 @@ TEST_F(DrmGemCloseWorkerTests, gemClose) {
|
||||||
|
|
||||||
auto worker = new DrmGemCloseWorker(*mm);
|
auto worker = new DrmGemCloseWorker(*mm);
|
||||||
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
||||||
auto alloc = new DrmAllocationWrapper(bo);
|
|
||||||
|
|
||||||
worker->push(alloc);
|
worker->push(bo);
|
||||||
|
|
||||||
delete worker;
|
delete worker;
|
||||||
}
|
}
|
||||||
|
@ -124,9 +123,8 @@ TEST_F(DrmGemCloseWorkerTests, gemCloseExit) {
|
||||||
|
|
||||||
auto worker = new DrmGemCloseWorker(*mm);
|
auto worker = new DrmGemCloseWorker(*mm);
|
||||||
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
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
|
//wait for worker to complete or deadCnt drops
|
||||||
while (!worker->isEmpty() && (deadCnt-- > 0))
|
while (!worker->isEmpty() && (deadCnt-- > 0))
|
||||||
|
@ -145,9 +143,8 @@ TEST_F(DrmGemCloseWorkerTests, close) {
|
||||||
|
|
||||||
auto worker = new DrmGemCloseWorker(*mm);
|
auto worker = new DrmGemCloseWorker(*mm);
|
||||||
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
||||||
auto alloc = new DrmAllocationWrapper(bo);
|
|
||||||
|
|
||||||
worker->push(alloc);
|
worker->push(bo);
|
||||||
worker->close(false);
|
worker->close(false);
|
||||||
|
|
||||||
//wait for worker to complete or deadCnt drops
|
//wait for worker to complete or deadCnt drops
|
||||||
|
@ -164,10 +161,9 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl
|
||||||
|
|
||||||
auto worker = new DrmGemCloseWorker(*mm);
|
auto worker = new DrmGemCloseWorker(*mm);
|
||||||
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
auto bo = new BufferObjectWrapper(this->drmMock, 1);
|
||||||
auto alloc = new DrmAllocationWrapper(bo);
|
|
||||||
|
|
||||||
bo->reference();
|
bo->reference();
|
||||||
worker->push(alloc);
|
worker->push(bo);
|
||||||
|
|
||||||
auto r = mm->unreference(bo, true);
|
auto r = mm->unreference(bo, true);
|
||||||
EXPECT_EQ(1u, r);
|
EXPECT_EQ(1u, r);
|
||||||
|
|
Loading…
Reference in New Issue