Skip to content
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

4.x: Inline Disposable.Create #580

Merged
merged 3 commits into from
Jun 11, 2018

Conversation

akarnokd
Copy link
Collaborator

@akarnokd akarnokd commented Jun 9, 2018

This PR inlines the Disposable.Create(Action) invocations, saving on an allocation and some indirection.

SetUpstream(StableCompositeDisposable.Create(fstSubscription, sndSubscription, fstO, sndO));
// clearing the queue should happen under the lock
// as they are plain Queue<T>s, not concurrent queues.
lock (_gate)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has now become dangerous, _gate might not be assigned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can Dispose happen before Run executes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hopefully not in our code, but it's good to assume everything might be disposed right away. By the same reasoning, Run will definitely happen when the Sink was created, so the gate might be created while constructing.

{
Disposable.TryDispose(ref _subscriptions[i]);
}
lock (_gate)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has now become dangerous, _gate might not be assigned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll move the creation into the constructor so it will be guaranteed to exist.

{
var o = new SourceObserver(this, i);
Disposable.SetSingle(ref _subscriptions[i], srcs[i].SubscribeSafe(o));
_gate = new object();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it's safe now but please just make it a readonly field and assign it in the declaration.

@danielcweber danielcweber merged commit 6ecc899 into dotnet:master Jun 11, 2018
@akarnokd akarnokd deleted the DisposableCreateInline branch June 11, 2018 10:59
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.

2 participants