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

Avoid SerialPort IOLoop when there's no event handlers #102829

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

MrJul
Copy link
Contributor

@MrJul MrJul commented May 29, 2024

This PR avoids starting the SerialPort I/O loop uncondtionally on Unix.

dotnet/corefx#40383 added support for the PinChanged event on the Unix version of SerialStream.
However, since SerialPort was always subscribing to SerialStream.PinChanged, this had the side effect of always starting the IOLoop, even when no events were actually subscribed on the SerialPort.

This PR changes this behavior. SerialStream.PinChanged is only subscribed to if SerialPort.PinChanged has handlers.
This mimics the logic for the DataReceived event.

When no events are subscribed, opening a SerialPort without reading or writing now doesn't use any CPU.

First part of fixing #2379 (CPU usage still remains high when reading/writing).

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 29, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-ports
See info in area-owners.md if you want to be subscribed.

@ericstj
Copy link
Member

ericstj commented Nov 4, 2024

@krwq could you have a look at this?

@dotnet dotnet deleted a comment from azure-pipelines bot Nov 18, 2024
@krwq krwq merged commit d90ec84 into dotnet:main Nov 18, 2024
83 checks passed
@krwq
Copy link
Member

krwq commented Nov 18, 2024

Thanks @MrJul and really sorry for the super late review

mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO.Ports community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants