-
Notifications
You must be signed in to change notification settings - Fork 607
Use only one interrup callback for one chip. #2408
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
base: main
Are you sure you want to change the base?
Conversation
src/devices/Tca955x/Tca955x.cs
Outdated
@@ -434,7 +434,12 @@ protected override void AddCallbackForPinValueChangedEvent(int pinNumber, PinEve | |||
|
|||
_interruptPins.Add(pinNumber, eventType); | |||
_interruptLastInputValues.Add(pinNumber, Read(pinNumber)); | |||
_controller.RegisterCallbackForPinValueChangedEvent(_interrupt, PinEventTypes.Falling, InterruptHandler); | |||
|
|||
// Only register the callback if this is the first add callback |
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.
Can you improve a comment a bit to clarify that we need to register interrupt once for host but this logic is for extender interrupts therefore the single handler will handle all extender interrupts registrations
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.
(same for removal - it seems like many of us were confused about what's being fixed initially)
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 updated the comment so it should be now more clear why I register the callback for the interrupt only once
src/devices/Tca955x/Tca955x.cs
Outdated
_controller.RegisterCallbackForPinValueChangedEvent(_interrupt, PinEventTypes.Falling, InterruptHandler); | ||
|
||
// Only register the callback if this is the first add callback | ||
if (_interruptPins.Count == 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.
This class is not necessarily thread safe, but these checks are very likely to fail in any concurrent environment. Is it worth it to add a lock before these checks?
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 can lock (_interruptHandlerLock)
as we do elsewhere for all register/deregister
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.
Add lock on Add and Remove Callback
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 to me!
src/devices/Tca955x/Tca955x.cs
Outdated
_controller.RegisterCallbackForPinValueChangedEvent(_interrupt, PinEventTypes.Falling, InterruptHandler); | ||
} | ||
|
||
} | ||
|
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 think _eventHandlers[pinNumber] = ...
shuold also be inside the lock
{ | ||
_controller.RegisterCallbackForPinValueChangedEvent(_interrupt, PinEventTypes.Falling, InterruptHandler); | ||
} | ||
|
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: extra enter
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 with small comment
I think this should just sign up when the driver is created/disposed. See my implementation in #2417 Sorry, I didn't see this PR until just now. |
I got carried away and made the TCA955x work better. I dropped my other PR and opened another #2420 |
Prevent multiple callbacks on the interrupt pin. Only use one inpterrupt callback.
Fixing typos.
Code is test with a Tca9555 and Tca9554
Microsoft Reviewers: Open in CodeFlow