use a u64 for the handler id to avoid wrap around issues
This commit is contained in:
parent
ae2cc463db
commit
0355ad3dce
|
@ -1,6 +1,6 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicU64, Ordering},
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,14 +8,15 @@ pub type Handler = Box<dyn Fn() + Send + Sync>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Handlers {
|
pub struct Handlers {
|
||||||
handlers: Arc<Mutex<Vec<(usize, Handler)>>>,
|
handlers: Arc<Mutex<Vec<(u64, Handler)>>>,
|
||||||
next_id: Arc<AtomicUsize>,
|
// we use an u64 so an overflow is impractical
|
||||||
|
next_id: Arc<AtomicU64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Guard {
|
pub struct Guard {
|
||||||
id: usize,
|
id: u64,
|
||||||
handlers: Arc<Mutex<Vec<(usize, Handler)>>>,
|
handlers: Arc<Mutex<Vec<(u64, Handler)>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Guard {
|
impl Drop for Guard {
|
||||||
|
@ -36,7 +37,7 @@ impl Debug for Guard {
|
||||||
impl Handlers {
|
impl Handlers {
|
||||||
pub fn new() -> Handlers {
|
pub fn new() -> Handlers {
|
||||||
let handlers = Arc::new(Mutex::new(vec![]));
|
let handlers = Arc::new(Mutex::new(vec![]));
|
||||||
let next_id = Arc::new(AtomicUsize::new(0));
|
let next_id = Arc::new(AtomicU64::new(0));
|
||||||
Handlers { handlers, next_id }
|
Handlers { handlers, next_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user