This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rid of thread handles in favor of simple id-based map
- Loading branch information
1 parent
5820858
commit 013537b
Showing
10 changed files
with
153 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{ | ||
cell::RefCell, | ||
collections::{HashMap, HashSet}, | ||
rc::Rc, | ||
}; | ||
|
||
use crate::{thread_id::ThreadId, util::ThreadResult}; | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct ThreadResultMap { | ||
tracked: Rc<RefCell<HashSet<ThreadId>>>, | ||
inner: Rc<RefCell<HashMap<ThreadId, ThreadResult>>>, | ||
} | ||
|
||
impl ThreadResultMap { | ||
pub fn new() -> Self { | ||
Self { | ||
tracked: Rc::new(RefCell::new(HashSet::new())), | ||
inner: Rc::new(RefCell::new(HashMap::new())), | ||
} | ||
} | ||
|
||
pub fn track(&self, id: ThreadId) { | ||
self.tracked.borrow_mut().insert(id); | ||
} | ||
|
||
pub fn is_tracked(&self, id: ThreadId) -> bool { | ||
self.tracked.borrow().contains(&id) | ||
} | ||
|
||
pub fn insert(&self, id: ThreadId, result: ThreadResult) { | ||
assert!(self.is_tracked(id), "Thread must be tracked"); | ||
self.inner.borrow_mut().insert(id, result); | ||
} | ||
|
||
pub fn remove(&self, id: ThreadId) -> Option<ThreadResult> { | ||
let res = self.inner.borrow_mut().remove(&id)?; | ||
self.tracked.borrow_mut().remove(&id); | ||
Some(res) | ||
} | ||
} |
Oops, something went wrong.