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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MrJul
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

1 participant