Skip to content

Add a condition variable implementation to the sync module. - #104

Merged
wedsonaf merged 2 commits into
rustfrom
condvar
Mar 16, 2021
Merged

wedsonaf merged 2 commits into
rustfrom
condvar

Conversation

@wedsonaf

Copy link
Copy Markdown

This is on top of #103.

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early review with a couple of requests to save time later.

Comment thread drivers/char/rust_example.rs
Comment thread rust/kernel/sync/condvar.rs Outdated
Comment thread rust/kernel/sync/condvar.rs Outdated
Comment thread rust/kernel/sync/guard.rs
Comment thread rust/kernel/sync/condvar.rs

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I will merge it in a while in case @alex wants to take a final look.

@alex

ghost commented Mar 15, 2021

Copy link
Copy Markdown
Member

I don't feel like I know the relevant kernel APIs well enough, so please don't wait on my account.

condvar_init!(cv.as_ref(), "RustExample::init::cv1");
{
let guard = data.lock();
#[allow(clippy::while_immutable_condition)]

ghost Mar 15, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: will this make the following read on guard volatile? IOW, could there be anything that stops the compiler from optimizing the following code as

let c = *guard;
while c != 10{
    cv.wait(&guard);
}

ghost Mar 16, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the the interior mutability implied by the use of UnsafeCell prevents the compiler from assuming that *guard won't change: it calls deref(), which calls locked_data() from the underlying lock, which returns an UnsafeCell.

Comment thread rust/kernel/sync/condvar.rs Outdated
Fix comment.

Co-authored-by: Miguel Ojeda <ojeda@users.noreply.github.com>
@wedsonaf
wedsonaf merged commit 58ab534 into rust Mar 16, 2021
@wedsonaf
wedsonaf deleted the condvar branch March 16, 2021 11:07
@ojeda

ghost commented Mar 16, 2021

Copy link
Copy Markdown
Member

I was about to merge it, sorry -- I am juggling different things now. Please don't hesitate to ping me if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants