Fix named_thread_group constructor
m_count - 1 could underflow
This commit is contained in:
+5
-6
@@ -797,31 +797,30 @@ public:
|
|||||||
m_count = 0;
|
m_count = 0;
|
||||||
|
|
||||||
// Create all threads
|
// Create all threads
|
||||||
for (u32 i = 0; i < count - 1; i++)
|
for (; m_count < count - 1; m_count++)
|
||||||
{
|
{
|
||||||
// Copy the context
|
// Copy the context
|
||||||
std::remove_cvref_t<Context> context(static_cast<const Context&>(f));
|
std::remove_cvref_t<Context> context(static_cast<const Context&>(f));
|
||||||
|
|
||||||
// Perform the check and additional preparations for each context
|
// Perform the check and additional preparations for each context
|
||||||
if (!std::invoke(std::forward<CheckAndPrepare>(check), i, context))
|
if (!std::invoke(std::forward<CheckAndPrepare>(check), m_count, context))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_count++;
|
new (static_cast<void*>(m_threads + m_count)) Thread(std::string(name) + std::to_string(m_count + 1), std::move(context));
|
||||||
new (static_cast<void*>(m_threads + i)) Thread(std::string(name) + std::to_string(i + 1), std::move(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the context (if movable)
|
// Move the context (if movable)
|
||||||
std::remove_cvref_t<Context> context(std::forward<Context>(f));
|
std::remove_cvref_t<Context> context(std::forward<Context>(f));
|
||||||
|
|
||||||
if (!std::invoke(std::forward<CheckAndPrepare>(check), m_count - 1, context))
|
if (!std::invoke(std::forward<CheckAndPrepare>(check), m_count, context))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new (static_cast<void*>(m_threads + m_count)) Thread(std::string(name) + std::to_string(m_count + 1), std::move(context));
|
||||||
m_count++;
|
m_count++;
|
||||||
new (static_cast<void*>(m_threads + m_count - 1)) Thread(std::string(name) + std::to_string(m_count - 1), std::move(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
|
|||||||
Reference in New Issue
Block a user