wayland: global counter for client serials
This commit is contained in:
parent
a77e29d9b5
commit
1301fb6e62
|
@ -12,8 +12,41 @@
|
||||||
//! destroy the global at all, you don't need to bother keeping the
|
//! destroy the global at all, you don't need to bother keeping the
|
||||||
//! `Global` around.
|
//! `Global` around.
|
||||||
|
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
pub mod compositor;
|
pub mod compositor;
|
||||||
pub mod output;
|
pub mod output;
|
||||||
pub mod seat;
|
pub mod seat;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
pub mod shm;
|
pub mod shm;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
/// A global SerialCounter for use in your compositor.
|
||||||
|
///
|
||||||
|
/// Is is also used internally by some parts of Smithay.
|
||||||
|
pub static ref SERIAL_COUNTER: SerialCounter = SerialCounter {
|
||||||
|
serial: Mutex::new(0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A counter for generating serials, for use in the client protocol
|
||||||
|
///
|
||||||
|
/// A global instance of this counter is available as the `SERIAL_COUNTER`
|
||||||
|
/// static. It is recommended to only use this global counter to ensure the
|
||||||
|
/// uniqueness of serials.
|
||||||
|
///
|
||||||
|
/// The counter will wrap around on overflow, ensuring it can run for as long
|
||||||
|
/// as needed.
|
||||||
|
pub struct SerialCounter {
|
||||||
|
// TODO: replace with an AtomicU32 when stabilized
|
||||||
|
serial: Mutex<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SerialCounter {
|
||||||
|
/// Retrieve the next serial from the counter
|
||||||
|
pub fn next_serial(&self) -> u32 {
|
||||||
|
let guard = self.serial.lock().unwrap();
|
||||||
|
guard.wrapping_add(1);
|
||||||
|
*guard
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue