-
Notifications
You must be signed in to change notification settings - Fork 347
Extract awaitable support into a struct #1207
Conversation
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.
Looks good, small changes in the review comments.
- We should see if we can get cancellation in there.
src/System.IO.Pipelines/Pipe.cs
Outdated
_awaitableIsCompleted); | ||
} | ||
|
||
public bool IsCompleted() => ReferenceEquals(_state, _awaitableIsCompleted); |
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.
Property?
src/System.IO.Pipelines/Pipe.cs
Outdated
_readerCallback = _awaitableIsNotCompleted; | ||
_writerCallback = _awaitableIsCompleted; | ||
|
||
_readerAwaitable = new Awaitable(false, options.ReaderScheduler ?? InlineScheduler.Default); |
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.
Use optional parameter syntax and put the bool last. Makes it more obvious what it is.
{ | ||
internal partial class Pipe | ||
{ | ||
private struct Awaitable |
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.
Nit: Make PipeAwaitable a non-nested internal struct instead of using partial classes.
public static int NotActive = 0; | ||
public static int Active = 1; | ||
} | ||
|
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.
nit
@@ -448,8 +395,6 @@ void IPipeReader.Advance(ReadCursor consumed, ReadCursor examined) | |||
_length -= consumedBytes; | |||
resumeWriter = _length < _maximumSizeLow; | |||
|
|||
// Change the state from observed -> not cancelled. We only want to reset the cancelled state if it was observed | |||
Interlocked.CompareExchange(ref _cancelledState, CancelledState.NotCancelled, CancelledState.CancellationObserved); |
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.
Where does this happen?
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.
PipeAwaitable.Reset
@@ -5,6 +5,7 @@ | |||
<TargetFrameworks>net451;netstandard1.3</TargetFrameworks> | |||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
<PackageIconUrl>http://go.microsoft.com/fwlink/?linkid=833199</PackageIconUrl> | |||
<DefineConstants Condition="'$(Configuration)' == 'Debug'">OPERATION_LOCATION_TRACKING;COMPLETION_LOCATION_TRACKING</DefineConstants> |
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.
You need to keep the default <DefineConstants>
.
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);OPERATION_LOCATION_TRACKING;COMPLETION_LOCATION_TRACKING</DefineConstants>
CancelledState.NotCancelled, | ||
CancelledState.CancellationObserved); | ||
|
||
if (_cancelledState != CancelledState.CancellationRequested) |
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.
Take return value from the CompareExchange
above and use that instead? Rather than re-reading the value that's just been cpu pipeline invalidated
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.
It's done in other PR: #1209
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.
Concurrent PRs on concurrency, nice touch 😉
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.
I don't think this PR is meant to affect any of the logic. It's about code cleanliness.
2bf77b5
to
f7e401c
Compare
src/System.IO.Pipelines/Pipe.cs
Outdated
@@ -10,20 +10,20 @@ namespace System.IO.Pipelines | |||
/// <summary> | |||
/// Default <see cref="IPipeWriter"/> and <see cref="IPipeReader"/> implementation. | |||
/// </summary> | |||
internal class Pipe : IPipe, IPipeReader, IPipeWriter, IReadableBufferAwaiter, IWritableBufferAwaiter | |||
internal partial class Pipe : IPipe, IPipeReader, IPipeWriter, IReadableBufferAwaiter, IWritableBufferAwaiter |
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.
Remove the partial?
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.
LGTM
@davidfowl