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

backend: fix prepare_read behavior #650

Merged
merged 1 commit into from
Aug 26, 2023
Merged

Conversation

elinorbgr
Copy link
Member

This should fix the multithreading issues that have been encountered.

cc @kchibisov

@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Patch coverage: 76.47% and project coverage change: +0.02% 🎉

Comparison is base (952820c) 73.09% compared to head (e0372d0) 73.11%.

❗ Current head e0372d0 differs from pull request most recent head 69eae18. Consider uploading reports for the commit 69eae18 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #650      +/-   ##
==========================================
+ Coverage   73.09%   73.11%   +0.02%     
==========================================
  Files          47       47              
  Lines        7711     7691      -20     
==========================================
- Hits         5636     5623      -13     
+ Misses       2075     2068       -7     
Flag Coverage Δ
main 58.59% <52.94%> (+0.03%) ⬆️
test-- 78.09% <77.77%> (+<0.01%) ⬆️
test--server_system 61.29% <77.77%> (-0.02%) ⬇️
test-client_system- 69.12% <64.70%> (+0.01%) ⬆️
test-client_system-server_system 51.31% <64.70%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
wayland-backend/src/rs/wire.rs 93.33% <ø> (ø)
wayland-client/src/event_queue.rs 58.92% <50.00%> (+0.33%) ⬆️
wayland-backend/src/sys/client_impl/mod.rs 72.29% <75.00%> (+0.23%) ⬆️
wayland-client/src/conn.rs 85.83% <75.00%> (-0.35%) ⬇️
wayland-backend/src/client_api.rs 90.47% <100.00%> (ø)
wayland-backend/src/rs/client_impl/mod.rs 78.94% <100.00%> (ø)

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Probably the same about #[must_use] for other methods. Also, maybe we should use Result instead, but use some io type to indicate that lock can't be acquired? The mutex stuff uses Result and it's more intuitive than the Option.

wayland-client/src/conn.rs Show resolved Hide resolved
if let Some(guard) = self.backend.prepare_read() {
dispatched += blocking_read(guard)?;
} else {
dispatched += self.backend.dispatch_inner_queue()?;
Copy link
Member

Choose a reason for hiding this comment

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

Hm, but you could have a blocking dispatch of the queue here as well? Non-blocking roundtrip doesn't sound like it'll work reliably or I don't understand something?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in a loop, so it'll just try again at the next iteration.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yeah, sure, I just know that there's mo efficient API to do the exact same thing, but I think it's not an option for us. The wl_display_dispatch_queue https://wayland.freedesktop.org/docs/html/apb.html#Client-classwl__display_1ae027b09801474ac7c6b0f1ef25ff6e17

Copy link
Member Author

Choose a reason for hiding this comment

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

That function in wayland-client does mostly exactly the same thing as wl_display_roundtrip, but implemented in terms of wayland-backend's API, so I don't really get your point?

Copy link
Member

Choose a reason for hiding this comment

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

wl_display_roundtrip uses poll under the hood to not do the loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@elinorbgr if you look closely what their code is and what we have, they use blocking dispatch. However we use it only in read_guard branch, and the other branch is using regular non-blocking dispatch.

So while they have a loop, the wait, but we busy loop from the else. The blocking read is fine, the else is a busy loop. dispatch_inner_queue is a non_blocking API from what I can, see, but libwayland always using blocking API, with dispatch_queue.

Copy link
Member

Choose a reason for hiding this comment

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

After reading the libwayland impl it's pretty much the same, when their docs are not really clear what exactly blocks and how it works.

@elinorbgr
Copy link
Member Author

Also, maybe we should use Result instead, but use some io type to indicate that lock can't be acquired?

Not sure what we would gain from this? It feels to me that this Option<_> reflects best the behavior of this method, changing it to a Result we would just have an error type identical to (), what would be the point then?

@elinorbgr elinorbgr merged commit 799c772 into master Aug 26, 2023
16 checks passed
@elinorbgr elinorbgr deleted the elinorbgr/fix-backend-queue branch August 26, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants