From ad46489a9e77c7447a1fc2029c1c7134372e46e9 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 31 Aug 2024 10:29:06 +0300 Subject: [PATCH] Change IdCounter to be backed by an AtomicU64 Let's see if anyone complains. --- src/backend/mod.rs | 4 ++-- src/layout/workspace.rs | 4 ++-- src/utils/id.rs | 11 ++++------- src/window/mapped.rs | 4 ++-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 40edef324..bbacf1cf1 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -37,7 +37,7 @@ pub type IpcOutputMap = HashMap; static OUTPUT_ID_COUNTER: IdCounter = IdCounter::new(); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct OutputId(u32); +pub struct OutputId(u64); impl OutputId { fn next() -> OutputId { @@ -45,7 +45,7 @@ impl OutputId { } pub fn get(self) -> u64 { - u64::from(self.0) + self.0 } } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index da1be408b..26d6a7859 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -123,7 +123,7 @@ pub struct OutputId(String); static WORKSPACE_ID_COUNTER: IdCounter = IdCounter::new(); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct WorkspaceId(u32); +pub struct WorkspaceId(u64); impl WorkspaceId { fn next() -> WorkspaceId { @@ -131,7 +131,7 @@ impl WorkspaceId { } pub fn get(self) -> u64 { - u64::from(self.0) + self.0 } } diff --git a/src/utils/id.rs b/src/utils/id.rs index 94d7f8ee9..c21511e6d 100644 --- a/src/utils/id.rs +++ b/src/utils/id.rs @@ -1,11 +1,8 @@ -use std::sync::atomic::{AtomicU32, Ordering}; +use std::sync::atomic::{AtomicU64, Ordering}; /// Counter that returns unique IDs. -/// -/// Under the hood it uses a `u32` that will eventually wrap around. When incrementing it once a -/// second, it will wrap around after about 136 years. pub struct IdCounter { - value: AtomicU32, + value: AtomicU64, } impl IdCounter { @@ -13,11 +10,11 @@ impl IdCounter { Self { // Start from 1 to reduce the possibility that some other code that uses these IDs will // get confused. - value: AtomicU32::new(1), + value: AtomicU64::new(1), } } - pub fn next(&self) -> u32 { + pub fn next(&self) -> u64 { self.value.fetch_add(1, Ordering::Relaxed) } } diff --git a/src/window/mapped.rs b/src/window/mapped.rs index 60cf7cd9d..a2875d024 100644 --- a/src/window/mapped.rs +++ b/src/window/mapped.rs @@ -98,7 +98,7 @@ niri_render_elements! { static MAPPED_ID_COUNTER: IdCounter = IdCounter::new(); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct MappedId(u32); +pub struct MappedId(u64); impl MappedId { fn next() -> MappedId { @@ -106,7 +106,7 @@ impl MappedId { } pub fn get(self) -> u64 { - u64::from(self.0) + self.0 } }