Remove TaskGraph::Drain which was only added initially for testing

The drain function was used only before the API gained the ability to
wait on the completion of a graph. This is the correct way to "drain"
the task executor of work.

Signed-off-by: Jeremy Ong <jcong@amazon.com>
This commit is contained in:
Jeremy Ong
2021-08-06 03:02:41 -06:00
parent 4743ca8bc1
commit 4f9c2cf693
3 changed files with 1 additions and 111 deletions
@@ -355,24 +355,8 @@ namespace AZ
m_workers[++m_lastSubmission % m_threadCount].Enqueue(&task);
}
void TaskExecutor::Drain()
{
m_isDraining = true;
if (m_graphsRemaining == 0)
{
return;
}
m_drainSemaphore.acquire();
}
void TaskExecutor::ReleaseGraph()
{
uint64_t graphsRemaining = --m_graphsRemaining;
if (graphsRemaining == 0 && m_isDraining)
{
m_drainSemaphore.release();
m_isDraining = false;
}
--m_graphsRemaining;
}
} // namespace AZ
@@ -76,9 +76,6 @@ namespace AZ
void Submit(Internal::Task& task);
// Wait until tasks are cleared from the executor (note, does not prevent future tasks from being submitted)
// If this is used, it's expected to be used between frames to shutdown the engine
void Drain();
private:
friend class Internal::TaskWorker;
@@ -88,7 +85,5 @@ namespace AZ
uint32_t m_threadCount = 0;
AZStd::atomic<uint32_t> m_lastSubmission;
AZStd::atomic<uint64_t> m_graphsRemaining;
AZStd::atomic<bool> m_isDraining;
AZStd::binary_semaphore m_drainSemaphore;
};
} // namespace AZ
-89
View File
@@ -543,95 +543,6 @@ namespace UnitTest
EXPECT_EQ(3 | 0b100000, x);
}
TEST_F(TaskGraphTestFixture, ExecutorDrainRetained)
{
bool drainDone = false;
AZStd::binary_semaphore taskStart;
AZStd::binary_semaphore threadLaunched;
AZStd::binary_semaphore threadFinished;
TaskGraph graph;
auto a = graph.AddTask(
defaultTD,
[&]
{
taskStart.acquire();
});
graph.SubmitOnExecutor(*m_executor);
AZStd::thread drainThread{ [this, &drainDone, &threadLaunched, &threadFinished]
{
threadLaunched.release();
m_executor->Drain();
drainDone = true;
threadFinished.release();
} };
// Wait until our drain thread has launched
threadLaunched.acquire();
// The task itself hasn't started, so the drain should still be blocking
EXPECT_EQ(false, drainDone);
// Allow the task to finish
taskStart.release();
// Wait for the drain thread to wrap up
threadFinished.acquire();
// We successfully drained the executor
EXPECT_EQ(true, drainDone);
drainThread.join();
}
TEST_F(TaskGraphTestFixture, ExecutorDrainDetached)
{
bool drainDone = false;
AZStd::binary_semaphore taskStart;
AZStd::binary_semaphore threadLaunched;
AZStd::binary_semaphore threadFinished;
TaskGraph graph;
auto a = graph.AddTask(
defaultTD,
[&]
{
taskStart.acquire();
});
graph.Detach();
graph.SubmitOnExecutor(*m_executor);
AZStd::thread drainThread{ [this, &drainDone, &threadLaunched, &threadFinished]
{
threadLaunched.release();
m_executor->Drain();
drainDone = true;
threadFinished.release();
} };
// Wait until our drain thread has launched
threadLaunched.acquire();
// The task itself hasn't started, so the drain should still be blocking
EXPECT_EQ(false, drainDone);
// Allow the task to finish
taskStart.release();
// Wait for the drain thread to wrap up
threadFinished.acquire();
// We successfully drained the executor
EXPECT_EQ(true, drainDone);
drainThread.join();
}
} // namespace UnitTest
#if defined(HAVE_BENCHMARK)