-
Notifications
You must be signed in to change notification settings - Fork 7
Provide functions to get the global Collector #25
Comments
exposing the default
|
I like that, except it wouldn't work for a global handle because
What if a library has a function like Another way of doing it would be to add a |
This is similar to Rayon's pub fn global() -> &'static Arc<ThreadPool> {
// ...
} |
I agree. Currently the
As above, there is probably no need for a library to ever do that. |
OK, fair enough. I guess just a getter for the default TLS handle is enough. |
If we replace Non- // Increments a reference count, but should be very cheap since this is a non-atomic operation.
fn default_handle() -> Handle {
HANDLE.with(|h| h.clone())
}
// Cloning a handle returns just another reference to the same thing.
// This is the same idea as with `std::thread::Thread` -- cloning a `Thread` simply
// gives you another handle to the same thread.
pub struct Handle {
node: *const Node,
}
impl Clone for Handle {
fn clone(&self) -> Self {
unsafe {
*(*self.node).refcnt.get() += 1;
Handle { node: self.node }
}
}
}
impl Drop for Handle {
fn drop(&mut self) {
unsafe {
let cnt = &mut *(*self.node).refcnt.get();
*cnt -= 1;
if *cnt == 0 {
let guard = &unprotected();
(*self.node).next.fetch_or(1, SeqCst, guard);
}
}
}
}
// A node in the linked list of registered participants.
struct Node {
local: Local,
global: Arc<Global>,
refcnt: UnsafeCell<usize>,
next: Atomic<Node>,
} |
@stjepang What's the use of |
It's just the next-pointer in the linked list. I didn't manage to reuse the |
Nice. |
If code accepts a
Handle
or aCollector
that the user is expected to pass, it'd be nice for them to be able to opt out of having to manage their own GC by simply doingcrossbeam::global_collector()
orcrossbeam::global_collector().handle()
or something similar.The text was updated successfully, but these errors were encountered: