Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bthread_usleep return unexpected error #2511

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

chenBright
Copy link
Contributor

@chenBright chenBright commented Jan 17, 2024

What problem does this PR solve?

Issue Number:

Problem Summary:

#2435 的改动可能会导致bthread_usleep实际上成功执行,但是返回ESTOP失败。

_add_sleep_event函数中,在定时器添加成功后,e.meta->current_sleep = sleep_id之前,定时器执行,唤醒了协程。

sleep_id = get_global_timer_thread()->schedule(
ready_to_run_from_timer_thread, void_args,
butil::microseconds_from_now(e.timeout_us));
if (!sleep_id) {
// fail to schedule timer, go back to previous thread.
g->ready_to_run(e.tid);
return;
}
// Set TaskMeta::current_sleep which is for interruption.
const uint32_t given_ver = get_version(e.tid);
{
BAIDU_SCOPED_LOCK(e.meta->version_lock);
if (given_ver == *e.meta->version_butex && !e.meta->interrupted) {
e.meta->current_sleep = sleep_id;
return;
}
}

协程被唤醒后,current_sleep为0、interrupted为false,返回了ESTOP错误。

if (e.meta->current_sleep == 0 && !e.meta->interrupted) {
// Fail to `_add_sleep_event'.
errno = ESTOP;
return -1;
}

What is changed and the side effects?

Changed:

使用一个特定的成员变量代替current_sleep==0来表示定时器添加失败。

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性):


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

@chenBright
Copy link
Contributor Author

@wwbmmm 有空看看这个问题

@wwbmmm
Copy link
Contributor

wwbmmm commented Jan 23, 2024

LGTM

@wwbmmm wwbmmm merged commit f60af19 into apache:master Jan 31, 2024
18 checks passed
@chenBright chenBright deleted the fix_bthread_usleep branch January 31, 2024 06:37
jiangdongzi pushed a commit to jiangdongzi/brpc that referenced this pull request Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants