Skip to content

Split out synchronization from is_initialized#74

Closed
pitdicker wants to merge 7 commits intomatklad:masterfrom
pitdicker:split_acquire_from_is_initialized
Closed

Split out synchronization from is_initialized#74
pitdicker wants to merge 7 commits intomatklad:masterfrom
pitdicker:split_acquire_from_is_initialized

Conversation

@pitdicker
Copy link
Contributor

This is based on top of #72, only the last two commits are relevant.

Before using MaybeUninit there were two ways to check whether a OnceCell was initialized:

  1. call is_initialized, which had the side effect of acquiring the value.
  2. test if the option was Some, which didn't do any synchronization.

After #72 we just always call is_initialized. I would like to bring back the distinction:

  1. fn sync_get will check if it is initialized, acquire and return the value
  2. fn is_initialized will only check if it is initialized, without synchronizing.

This is the only change I would need to the sync module to be able to add an experimental implementation using consume. Do you think it makes sense on its own? And is the change small enough not to bother duplicating the sync module?

The last commit is optional. It seems nice if initialize would return value. This prevents an unnessecary unwrap in get_or_try_init, for which the code used an unsafe get_unchecked before to prevent.

This pull request was closed.
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.

1 participant