wayland_backend::sys::client

Struct ReadEventsGuard

Source
pub struct ReadEventsGuard { /* private fields */ }
Available on (crate features client_system or server_system) and crate feature client_system only.
Expand description

Guard for synchronizing event reading across multiple threads

If multiple threads need to read events from the Wayland socket concurrently, it is necessary to synchronize their access. Failing to do so may cause some of the threads to not be notified of new events, and sleep much longer than appropriate.

This guard is provided to ensure the proper synchronization is done. The guard is created using the Backend::prepare_read() method. And the event reading is triggered by consuming the guard using the ReadEventsGuard::read() method, synchronizing with other threads as necessary so that only one of the threads will actually perform the socket read.

If you plan to poll the Wayland socket for readiness, the file descriptor can be retrieved via the ReadEventsGuard::connection_fd() method. Note that for the synchronization to correctly occur, you must always create the ReadEventsGuard before polling the socket.

Dropping the guard is valid and will cancel the prepared read.

Implementations§

Source§

impl ReadEventsGuard

Source

pub fn connection_fd(&self) -> BorrowedFd<'_>

Access the Wayland socket FD for polling

Source

pub fn read(self) -> Result<usize, WaylandError>

Attempt to read events from the Wayland socket

If multiple threads have a live reading guard, this method will block until all of them are either dropped or have their read() method invoked, at which point one of the threads will read events from the socket and invoke the callbacks for the received events. All threads will then resume their execution.

This returns the number of dispatched events, or 0 if an other thread handled the dispatching. If no events are available to read from the socket, this returns a WouldBlock IO error.

Trait Implementations§

Source§

impl Debug for ReadEventsGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.