From 1618c45d4ebf2911c4284708edefe934139498cb Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sun, 7 Oct 2018 22:36:44 +0200 Subject: [PATCH] wayland: use AtomicUsize for SerialCounter --- src/wayland/mod.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 42fa86e..4d66942 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -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, + 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 } }