wayland: use AtomicUsize for SerialCounter

This commit is contained in:
Victor Berger 2018-10-07 22:36:44 +02:00 committed by Victor Berger
parent 8b66680097
commit 1618c45d4e
1 changed files with 9 additions and 13 deletions

View File

@ -12,7 +12,7 @@
//! destroy the global at all, you don't need to bother keeping the
//! `Global` around.
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};
pub mod compositor;
pub mod output;
@ -20,14 +20,12 @@ pub mod seat;
pub mod shell;
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 global SerialCounter for use in your compositor.
///
/// Is is also used internally by some parts of Smithay.
pub static SERIAL_COUNTER: SerialCounter = SerialCounter {
serial: AtomicUsize::new(0),
};
/// A counter for generating serials, for use in the client protocol
///
@ -39,14 +37,12 @@ lazy_static! {
/// as needed.
pub struct SerialCounter {
// TODO: replace with an AtomicU32 when stabilized
serial: Mutex<u32>,
serial: AtomicUsize,
}
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
self.serial.fetch_add(1, Ordering::AcqRel) as u32
}
}