Open
Conversation
This patch introduces thread-safe register read/write operations for the local backend using `direct_reg_access` via debugfs. It adds two new backend ops: - `reg_read()` - `reg_write()` These functions use file locking (`flock`) to ensure atomic access and prevent race conditions when multiple threads interact with the same register interface. The fallback logic in `iio_device_reg_read()` and `iio_device_reg_write()` is preserved for backends that do not implement these atomic operations. This improves reliability for multi-threaded applications using libiio with the local backend. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Contributor
|
Don't you want to fix this at the same time? |
Contributor
Author
Yes, I think this can be removed. The race condition won't happen on IIOD server anymore. |
Implement atomic register operations which ensures that a register read or a register write cannot be interrupted by other clients of IIOD. Advantages: - half round trips: single command vs write-address + read-value - binary addresses/values vs hex string converion On client-server compatibility: v1.0 clients can connect to v1.0+ servers (atomic ops used) v1.0 clients connecting to v0.x servers fall back to attribute method Signed-off-by: Dan Nechita <dan.nechita@analog.com>
2ba0f46 to
22331ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
Local Backend
First patch introduces thread-safe register read/write operations for the local backend using
direct_reg_accessvia debugfs. It adds two new backend ops:reg_read()reg_write()These functions use file locking (
flock) to ensure atomic access and prevent race conditions when multiple threads interact with the same register interface.The fallback logic in
iio_device_reg_read()andiio_device_reg_write()is preserved for backends that do not implement these atomic operations.This improves reliability for multi-threaded applications using libiio with the local backend.
Network, USB and Serial Backends
Second patch implement atomic register operations which ensures that a register read or a register write cannot be interrupted by other clients of IIOD.
Advantages:
On client-server compatibility:
v1.0 clients can connect to v1.0+ servers (atomic ops used)
v1.0 clients connecting to v0.x servers fall back to attribute method
Closes #1351.
PR Type
PR Checklist