Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ public static void SetDisplayRotationCapability(Rotation rotation, MediaControlC

command.SetRequestInformation(clientId);

var tcs = new TaskCompletionSource<int>();
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
string reqeustId = null;
Bundle bundle = null;

Expand Down Expand Up @@ -909,7 +909,7 @@ public static async Task<Bundle> RequestAsync(Command command, string clientId)

command.SetRequestInformation(clientId);

var tcs = new TaskCompletionSource<int>();
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
string reqeustId = null;
Bundle bundle = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ public IEnumerable<Rotation> GetDisplayRotationCapability()

command.SetRequestInformation(ServerAppId);

var tcs = new TaskCompletionSource<int>();
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
string reqeustId = null;
Bundle bundle = null;

Expand Down Expand Up @@ -918,7 +918,7 @@ public async Task<Bundle> RequestAsync(Command command)

command.SetRequestInformation(ServerAppId);

var tcs = new TaskCompletionSource<int>();
var tcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
string reqeustId = null;
Bundle bundle = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private void PrepareCore(Display display, ScreenMirroringResolutions resolutions

private Task RunAsync(Func<IntPtr, ScreenMirroringErrorCode> func, string failMessage)
{
var tcs = new TaskCompletionSource<bool>();
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The RunAsync method can be simplified by returning the Task from Task.Run directly, rather than wrapping it in a redundant TaskCompletionSource<bool>. Since RunAsync returns a non-generic Task, the bool result is ignored anyway.

Refactoring this avoids the allocation of the TaskCompletionSource and its associated task, and simplifies error propagation.

For example:

private Task RunAsync(Func<IntPtr, ScreenMirroringErrorCode> func, string failMessage)
{
    return Task.Run(() =>
    {
        var ret = func(Handle);

        if (ret != ScreenMirroringErrorCode.None)
        {
            throw ret.AsException(failMessage);
        }
    });
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 [AI Review]
Addressed in 64f1117.


Task.Run(() =>
{
Expand Down
6 changes: 3 additions & 3 deletions src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public async Task StartAsync()

ValidateWebRTCState(WebRTCState.Idle);

var tcs = new TaskCompletionSource<bool>();
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Now that TaskCreationOptions.RunContinuationsAsynchronously is specified on the TaskCompletionSource, the continuation of await tcs.Task is guaranteed to execute asynchronously on the thread pool.

As a result, the await Task.Yield(); on line 196 is redundant and can be safely removed to avoid unnecessary context switching and thread rescheduling.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 [AI Review]
Addressed in 64f1117.

var error = WebRTCError.ConnectionFailed;

EventHandler<WebRTCStateChangedEventArgs> stateChangedEventHandler = (s, e) =>
Expand Down Expand Up @@ -244,7 +244,7 @@ public async Task<string> CreateOfferAsync()

ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);

var tcsSdpCreated = new TaskCompletionSource<string>();
var tcsSdpCreated = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Now that TaskCreationOptions.RunContinuationsAsynchronously is specified on tcsSdpCreated, the continuation of await tcsSdpCreated.Task is guaranteed to execute asynchronously on the thread pool.

Therefore, the await Task.Yield(); on line 261 is redundant and can be safely removed to avoid unnecessary context switching and thread rescheduling.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 [AI Review]
Addressed in 64f1117.


NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) =>
{
Expand Down Expand Up @@ -283,7 +283,7 @@ public async Task<string> CreateAnswerAsync()

ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);

var tcsSdpCreated = new TaskCompletionSource<string>();
var tcsSdpCreated = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Now that TaskCreationOptions.RunContinuationsAsynchronously is specified on tcsSdpCreated, the continuation of await tcsSdpCreated.Task is guaranteed to execute asynchronously on the thread pool.

Therefore, the await Task.Yield(); on line 300 is redundant and can be safely removed to avoid unnecessary context switching and thread rescheduling.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 [AI Review]
Addressed in 64f1117.


NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) =>
{
Expand Down
Loading