-
Notifications
You must be signed in to change notification settings - Fork 782
Use the helper methods for IDisposable-fields, avoid repeating code patterns #556
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
Use the helper methods for IDisposable-fields, avoid repeating code patterns #556
Conversation
|
|
||
| Context = context; | ||
| _disposable = disposable; | ||
| Disposable.TrySetSingle(ref _disposable, disposable); |
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.
Is TrySetSingle required here?
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.
This is in the constructor so nothing else should be able to call ContextDisposable.Dispose() at this point.
|
|
||
| Scheduler = scheduler; | ||
| _disposable = disposable; | ||
| Disposables.Disposable.TrySetSingle(ref _disposable, disposable); |
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.
Is TrySetSingle required here?
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.
Same as above, this is in the constructor where it can't be disposed yet.
| Drain(); | ||
| } | ||
| } | ||
| if (Disposable.TrySetSerial(ref currentSubscription, null)) |
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.
Does this still capture the original semantics?
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.
There is a loop in TrySetSerial where a concurrent dispose failing the CAS will have it repeat the loop, detect that it needs to dispose d and then quits. This logic relies on the fact that if the single CAS fails, it can be only due to cancellation and there is nothing to do further.
|
@akarnokd I added some notes for further review, thx. |
| var sad = new SingleAssignmentDisposable(); | ||
| if (Interlocked.CompareExchange(ref currentSubscription, sad, null) == null) | ||
|
|
||
| if (Disposable.TrySetSingle(ref currentSubscription, sad) == TrySetSingleResult.Success) |
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.
@akarnokd This change was added (the original reason to split SetSingle and TrySetSingle).
No description provided.