Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

CoreFx #16274 - LazyInitializer.EnsureInitialized overload for reference types#2868

Merged
jkotas merged 1 commit into
dotnet:masterfrom
WinCPP:LazyInitializerOverloads
Mar 2, 2017
Merged

CoreFx #16274 - LazyInitializer.EnsureInitialized overload for reference types#2868
jkotas merged 1 commit into
dotnet:masterfrom
WinCPP:LazyInitializerOverloads

Conversation

@WinCPP
Copy link
Copy Markdown
Contributor

@WinCPP WinCPP commented Mar 2, 2017

This is port of #16274

LazyInitializer.EnsureInitialized overload for reference types that does not take boolean for tracking initialization status of the reference type object. Null check on the object parameter is sufficient to whether
or not it has been initialized.

@stephentoub @karelz please review.

@dnfclas
Copy link
Copy Markdown

dnfclas commented Mar 2, 2017

@WinCPP,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot


return EnsureInitializedCore<T>(ref target, valueFactory);
}
// Another occurrence at line 183.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why Volatile.Read is not used in some places, e.g. line below and it is used in EnsureInitializedCore @ line 203.

Copy link
Copy Markdown
Member

@jkotas jkotas Mar 2, 2017

Choose a reason for hiding this comment

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

The comment right above this explains the original reason. It is not applicable anymore. The Volatile.Read performance issue has been fixed a long time ago. Could you please delete the comment and use Volatile.Read just like in CoreCLR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jkotas, not being very sure, I thought I would check as there was mix of styles. I have made changes in both the places.

// According to the abstract ECMA CLI memory model, this read should be volatile, due to possible reorderings with
// subsequent reads from fields of "target." However, as of today (7/12/12), Volatile.Read<T> is quite slow, and in practice
// this read does *not* need to be volatile, because our memory model preserves ordering of data-dependent reads.
// Another occurrence at line 86.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have changed Volatile.Read to normal read to match that at line 86. Please check the comment at line 182 and 85. Will remove those comments if inappropriate. Kindly advise.

not take boolean for tracking initialization status of the reference
type object. Null check on the object parameter is sufficient to whether
or not it has been initialized.
@WinCPP WinCPP force-pushed the LazyInitializerOverloads branch from 1a7a7ec to ffb31b7 Compare March 2, 2017 17:59
@jkotas
Copy link
Copy Markdown
Member

jkotas commented Mar 2, 2017

Thanks!

@jkotas jkotas merged commit ef78947 into dotnet:master Mar 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants