Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Extract awaitable support into a struct #1207

Merged
merged 10 commits into from
Feb 11, 2017
Merged

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Feb 9, 2017

@halter73
Copy link
Member

halter73 commented Feb 9, 2017

:shipit:

Copy link
Member

@davidfowl davidfowl left a 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.

_awaitableIsCompleted);
}

public bool IsCompleted() => ReferenceEquals(_state, _awaitableIsCompleted);
Copy link
Member

Choose a reason for hiding this comment

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

Property?

_readerCallback = _awaitableIsNotCompleted;
_writerCallback = _awaitableIsCompleted;

_readerAwaitable = new Awaitable(false, options.ReaderScheduler ?? InlineScheduler.Default);
Copy link
Member

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
Copy link
Member

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;
}

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

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

Where does this happen?

Copy link
Contributor Author

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>
Copy link
Member

@davidfowl davidfowl Feb 10, 2017

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)
Copy link
Member

@benaadams benaadams Feb 10, 2017

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

Copy link
Contributor Author

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

Copy link
Member

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 😉

Copy link
Member

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Remove the partial?

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

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

LGTM

@pakrym pakrym merged commit b150a99 into master Feb 11, 2017
@pakrym pakrym deleted the pakrym/extract-awaitable branch February 28, 2017 16:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants