<NME> mod.rs
<BEF> //! Protocol-related utilities
//!
//! This module contains several handlers to manage the Wayland protocol
//! and the clients.
//!
//! ## General structure
//!
//! Most utilities provided in this module work in the same way:
//!
//! - A module specific `*State` struct will take the wayland display as argument and
//!   insert one or more globals into it through its constructor.
//!   destroy the global at all, you don't need to bother keeping the
//!   `Global` around.

use std::sync::Mutex;

pub mod compositor;
pub mod output;
//!
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 counter for generating serials, for use in the client protocol
///
//! to forward input (such as pointer action or keystrokes) to clients, and manage the input
//! focus of clients. Tightly coupled with it is the [`data_device`] module, which handles
//! cross-client interactions such as accessing the clipboard, or drag'n'drop actions.
//!
//! The [`shm`] module provides the necessary logic for client to provide buffers defining the
/// 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
    }
}
pub mod compositor;
pub mod data_device;
pub mod dmabuf;
pub mod input_method;
pub mod keyboard_shortcuts_inhibit;
pub mod output;
pub mod primary_selection;
pub mod seat;
pub mod shell;
pub mod shm;
pub mod socket;
pub mod tablet_manager;
pub mod text_input;
pub mod viewporter;
pub mod virtual_keyboard;
pub mod xdg_activation;

<MSG> wayland: use AtomicUsize for SerialCounter

<DFF> @@ -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
     }
 }

wayland: use AtomicUsize for SerialCounter