-
Notifications
You must be signed in to change notification settings - Fork 47
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
utils: overhaul ImmutAfterInitCell
#595
Open
msft-jlange
wants to merge
5
commits into
coconut-svsm:main
Choose a base branch
from
msft-jlange:immut
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msft-jlange
force-pushed
the
immut
branch
2 times, most recently
from
January 22, 2025 05:30
2f1186b
to
8d20675
Compare
joergroedel
reviewed
Jan 22, 2025
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.
Overall the changes look good to me. There are a few open questions about using atomics and ordering I'd like to get sorted before merging.
The reinitialization behavior of `ImmutAfterInitCell` is not safe because it permits safe code to reinitialize a cell while another thread may be borrowing the contents of the cell. The most effective way to avoid this conflict is to remove the support for reinitialization. This also means that there is no need to support construction of an `ImmutAfterInitCell` with initialized contents. Signed-off-by: Jon Lange <[email protected]>
Safety requires enforcement of soundness rules in all configurations, not just those that enable debug assertions. The initialization guards of `ImmutAfterInitCell` should therefore not rely on debug assertions. In addition, they should be enforced using atomic initialization guards to ensure that initialization is safe with respect to possible preemption by interrupt or exception handlers. By making initialization fully `Sync` compliant, there is no need to require initialization to complete prior to multi-processor startup. Signed-off-by: Jon Lange <[email protected]>
The `try_get_inner()` function is used to obtain the contents of an `ImmutAfterInitCell` (or to return an error). It should be possible for a caller to obtain a `Result` instead of being forced to derefence and panic if the cell is not initialized. Signed-off-by: Jon Lange <[email protected]>
For maximum usefulness, it should be possible to support `ImmutAfterInitCell` for types that do not implement `Copy`. For example, some structures that require global initialization may contain atomics, which do not support `Copy`. However, it is also important not to require all initialization to be performed using moves, since a move into a cell requires a temporary copy on the stack, and some global types are especially large. Therefore `ImmutAfterInitCell` can support move-based initialization for all types, and by-reference initialization for types that support `Copy`. Signed-off-by: Jon Lange <[email protected]>
Add unit tests to validate the behavior of `ImmutAfterInitCell`. Signed-off-by: Jon Lange <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change updates the design of
ImmutAfterInitCell
to resolve the issues described in #591, making it behave much more like aSync
version ofOnceCell
.