hawkw / sharded-slab

a lock-free concurrent slab (experimental)
MIT License
269 stars 17 forks source link

feat(Pool): change `Pool::create` to return a mutable guard #48

Closed hawkw closed 3 years ago

hawkw commented 3 years ago

This PR changes the Pool::create method to return a RefMut guard, which allows mutable access to the new pooled item, rather than taking a closure that is used to initialize the item. A new method, Pool::create_with, provides the old behavior.

When a slot is referenced by a RefMut guard, it may not be accessed by other threads. Calls to Pool::get with that value's key will return None while a RefMut exists. The RefMut guard may be downgraded to an immutable Ref guard, allowing other threads to access the pooled item while retaining a guard for immutably accessing it.

Closes #41. Fixes #16.

BREAKING CHANGE:

Changed Pool::create to return a RefMut, rather than taking a closure and returning a key.

Renamed PoolGuard to pool::Ref.