Worker thread per plugin instance.
This commit is contained in:
+24
-8
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
// (Borrows heavily from worker.c by David Robillard.)
|
||||
|
||||
// Copyright (c) 2022 Robin Davies
|
||||
// Copyright (c) 2024 Robin Davies
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
@@ -242,8 +242,19 @@ void HostWorkerThread::ThreadProc() noexcept
|
||||
HostWorkerThread::HostWorkerThread()
|
||||
{
|
||||
this->dataBuffer.resize(16*1024);
|
||||
pThread = std::make_unique<std::thread>([this]()
|
||||
{ this->ThreadProc(); });
|
||||
}
|
||||
|
||||
bool HostWorkerThread::StartThread()
|
||||
{
|
||||
if (!pThread)
|
||||
{
|
||||
if (closed) {
|
||||
return false;
|
||||
}
|
||||
pThread = std::make_unique<std::thread>([this]()
|
||||
{ this->ThreadProc(); });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostWorkerThread::Close()
|
||||
@@ -252,10 +263,12 @@ void HostWorkerThread::Close()
|
||||
bool sendClose = false;
|
||||
{
|
||||
std::lock_guard lock{submitMutex};
|
||||
if (!closed)
|
||||
{
|
||||
closed = true;
|
||||
sendClose = true;
|
||||
if (pThread) {
|
||||
if (!closed)
|
||||
{
|
||||
closed = true;
|
||||
sendClose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sendClose)
|
||||
@@ -278,7 +291,10 @@ LV2_Worker_Status HostWorkerThread::ScheduleWork(Worker *worker, size_t size, co
|
||||
{
|
||||
std::lock_guard lock(submitMutex);
|
||||
|
||||
if (exiting)
|
||||
if (!StartThread()) { // ensures thread is running, when plugins haven't declared they want a worker thread.
|
||||
return LV2_Worker_Status::LV2_WORKER_ERR_NO_SPACE;
|
||||
}
|
||||
if (exiting )
|
||||
{
|
||||
return LV2_Worker_Status::LV2_WORKER_ERR_NO_SPACE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user