Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions umd/core/src/runtime/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ bool Emulator::ping()

NvDlaError Emulator::submit(NvU8* task_mem, bool blocking)
{
m_taskQueue.push(task_mem);
{
std::lock_guard<std::mutex> lk(m_mtx);
m_taskQueue.push(task_mem);
}

m_cv.notify_all();
if (blocking) {
// wait until queue becomes empty
while (!m_taskQueue.empty()) {
NvDlaThreadYield();
}
// wait until queue becomes empty
std::unique_lock<std::mutex> lk(m_mtx);
m_cv.wait(lk, [&]{return !(!m_taskQueue.empty() || m_signalShutdown);});
}

return NvDlaSuccess;
Expand Down Expand Up @@ -97,6 +100,7 @@ bool Emulator::stop()
if (m_thread)
{
m_signalShutdown = true;
m_cv.notify_all();
NvDlaThreadJoin(m_thread);
m_thread = NULL;
}
Expand All @@ -115,7 +119,14 @@ bool Emulator::run()

while (true)
{
if (!m_taskQueue.empty())
std::unique_lock<std::mutex> lk(m_mtx);
m_cv.wait(lk, [&]{return (!m_taskQueue.empty() || m_signalShutdown);});

if (m_signalShutdown)
{
break;
}
else if (!m_taskQueue.empty())
{
NvU8* task_mem = m_taskQueue.front();
NvDlaDebugPrintf("Work Found!\n");
Expand Down Expand Up @@ -145,25 +156,18 @@ bool Emulator::run()
NvDlaDebugPrintf("Work Done\n");

m_taskQueue.pop();
continue;
}

if (m_signalShutdown)
{
NvDlaDebugPrintf("Shutdown signal received, exiting\n");
break;
m_cv.notify_one();
}
}

if (m_taskQueue.empty())
{
NvDlaSleepMS(500);
}
}

// Cleanup
while (!m_taskQueue.empty())
{
m_taskQueue.pop();
std::lock_guard<std::mutex> lk(m_mtx);
while (!m_taskQueue.empty())
{
m_taskQueue.pop();
}
}

delete emu_if;
Expand Down
5 changes: 5 additions & 0 deletions umd/core/src/runtime/include/priv/Emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define NVDLA_PRIV_EMULATOR_H

#include <queue>
#include <mutex>
#include <condition_variable>

#include "priv/EMUInterface.h"

Expand Down Expand Up @@ -78,6 +80,9 @@ class Emulator
bool m_threadActive;

bool m_signalShutdown;

std::mutex m_mtx;
std::condition_variable m_cv;
};

} // nvdla::priv
Expand Down