mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
Reduce the number of lock releases and reacquires in the BckSchPoolDelay thread
This commit is contained in:
parent
1418e339e4
commit
0a057695aa
@ -258,38 +258,46 @@ void BackgroundSchedulePool::delayExecutionThreadFunction()
|
||||
while (!shutdown)
|
||||
{
|
||||
TaskHandle task;
|
||||
bool found = false;
|
||||
|
||||
{
|
||||
std::unique_lock lock(delayed_tasks_lock);
|
||||
|
||||
if(shutdown)
|
||||
break;
|
||||
|
||||
Poco::Timestamp min_time;
|
||||
|
||||
if (!delayed_tasks.empty())
|
||||
while(!shutdown)
|
||||
{
|
||||
auto t = delayed_tasks.begin();
|
||||
min_time = t->first;
|
||||
task = t->second;
|
||||
}
|
||||
Poco::Timestamp min_time;
|
||||
|
||||
if (!task)
|
||||
{
|
||||
wakeup_cond.wait(lock);
|
||||
continue;
|
||||
}
|
||||
if (!delayed_tasks.empty())
|
||||
{
|
||||
auto t = delayed_tasks.begin();
|
||||
min_time = t->first;
|
||||
task = t->second;
|
||||
}
|
||||
|
||||
Poco::Timestamp current_time;
|
||||
if (!task)
|
||||
{
|
||||
wakeup_cond.wait(lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (min_time > current_time)
|
||||
{
|
||||
wakeup_cond.wait_for(lock, std::chrono::microseconds(min_time - current_time));
|
||||
continue;
|
||||
Poco::Timestamp current_time;
|
||||
|
||||
if (min_time > current_time)
|
||||
{
|
||||
wakeup_cond.wait_for(lock, std::chrono::microseconds(min_time - current_time));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/// We have a task ready for execution
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task->schedule();
|
||||
if(found)
|
||||
task->schedule();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user