Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,21 +432,14 @@ impl Runtime {
}

fn generate_cb_identity(&mut self) -> usize {
let ident = self.generate_identity();
let taken = self.callback_queue.contains_key(&ident);

// if there is a collision or the identity is already there we loop until we find a new one
// we don't cover the case where there are `usize::MAX` number of callbacks waiting since
// that if we're fast and queue a new event every nanosecond that will still take 585.5 years
// to do on a 64 bit system.
if !taken {
ident
} else {
loop {
let possible_ident = self.generate_identity();
if self.callback_queue.contains_key(&possible_ident) {
break possible_ident;
}
loop {
let ident = self.generate_identity();
if !self.callback_queue.contains_key(&ident) {
break ident;
}
}
}
Expand Down