Make CrateMetadata and CStore thread-safe#48936
Conversation
0d9b6ee to
2de21be
Compare
michaelwoerister
left a comment
There was a problem hiding this comment.
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.
src/librustc_metadata/creader.rs
Outdated
There was a problem hiding this comment.
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.
parking_lot::Once looks like a good building block for such a thing.
|
I did think about adding something like |
| } | ||
|
|
||
| /// 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.
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 CrateNums based on that.
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