Skip to content

Commit 0ab0b69

Browse files
committed
wait_task busy loop before waiting on PL
1 parent e5f06dc commit 0ab0b69

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/bthread/task_group.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,23 @@ bool TaskGroup::is_stopped(bthread_t tid) {
116116
}
117117

118118
bool TaskGroup::wait_task(bthread_t* tid) {
119+
int64_t poll_start_ms = butil::cpuwide_time_ms();
119120
do {
120121
#ifndef BTHREAD_DONT_SAVE_PARKING_STATE
121122
if (_last_pl_state.stopped()) {
122123
return false;
123124
}
124125

125-
if (pop_resume_task(tid)) {
126+
if (pop_resume_task(tid) || steal_task(tid)) {
126127
return true;
127128
}
128129

129-
_pl->wait(_last_pl_state);
130+
// keep polling for some time before waiting on parking lot
131+
if (butil::cpuwide_time_ms() - poll_start_ms > 100) {
132+
_pl->wait(_last_pl_state);
133+
poll_start_ms = butil::cpuwide_time_ms();
134+
}
135+
130136
if (steal_task(tid)) {
131137
return true;
132138
}

0 commit comments

Comments
 (0)