-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make CrateMetadata and CStore thread-safe #48936
Conversation
0d9b6ee
to
2de21be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Zoxc! Looks good to me.
What do you think of adding an InitOnce<T>
primitive to rustc_data_structures::sync
? Especially things like codemap_import_info
would profit from this, I think. I haven't done any performance testing but even if it's not significantly faster, it makes the semantics much clearer which is always a win.
@@ -335,7 +334,9 @@ impl<'a> CrateLoader<'a> { | |||
if data.root.macro_derive_registrar.is_some() { | |||
dep_kind = DepKind::UnexportedMacrosOnly; | |||
} | |||
data.dep_kind.set(cmp::max(data.dep_kind.get(), dep_kind)); | |||
data.dep_kind.with_lock(|data_dep_kind| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add a separate primitive for state that is initialized once and then never modified again. There must be more efficient ways to do this than a mutex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parking_lot::Once
looks like a good building block for such a thing.
I did think about adding something like |
metadata_loader, | ||
} | ||
} | ||
|
||
/// You cannot use this function to allocate a CrateNum in a thread-safe manner. | ||
/// It is currently only used in CrateLoader which is single-threaded code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment about this function. next_crate_num
is used once in CrateLoader
to get the next free CrateNum
. CrateLoader
may then create multiple CrateNum
s based on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
At least for |
📌 Commit 5b8f9c5 has been approved by |
Make CrateMetadata and CStore thread-safe r? @michaelwoerister
☀️ Test successful - status-appveyor, status-travis |
r? @michaelwoerister