mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 23:11:01 +01:00
Add some more comments about Access and Token'
This commit is contained in:
1 parent
6085dcf33b
commit
1ed15f94dc
4 files changed
+22
-11
No files matched your search
@@ -258,9 +258,9 @@ type DeviceToken<'a> = Token<'a, Device<back::Backend>>;
|
||||
impl PendingResources<back::Backend> {
|
||||
fn triage_referenced(&mut self, trackers: &mut TrackerSet, mut token: &mut DeviceToken) {
|
||||
// Before destruction, a resource is expected to have the following strong refs:
|
||||
// 1. in resource itself
|
||||
// 2. in the device tracker
|
||||
// 3. in this list
|
||||
// - in resource itself
|
||||
// - in the device tracker
|
||||
// - in this list
|
||||
const MIN_REFS: usize = 4;
|
||||
|
||||
if self.referenced.iter().all(|r| r.1.load() >= MIN_REFS) {
|
||||
|
||||
+15
-3
@@ -136,15 +136,22 @@ impl<T, I: TypedId> Storage<T, I> {
|
||||
|
||||
|
||||
/// Type system for enforcing the lock order on shared HUB structures.
|
||||
/// The main property we are trying to establish is that each type
|
||||
/// of resources have only a single path from Root{} to reach by,
|
||||
/// when locking multiple resources types.
|
||||
/// If type A implements `Access<B>`, that means we are allowed to proceed
|
||||
/// with locking resource `B` after we lock `A`.
|
||||
///
|
||||
/// The implenentations basically describe the edges in a directed graph
|
||||
/// of lock transitions. As long as it doesn't have loops, we can have
|
||||
/// multiple concurrent paths on this graph (from multiple threads) without
|
||||
/// deadlocks, i.e. there is always a path whose next resource is not locked
|
||||
/// by some other path, at any time.
|
||||
pub trait Access<B> {}
|
||||
|
||||
pub enum Root {}
|
||||
//TODO: establish an order instead of declaring all the pairs.
|
||||
#[cfg(not(feature = "gfx-backend-gl"))]
|
||||
impl Access<InstanceHandle> for Root {}
|
||||
impl Access<SurfaceHandle> for Root {}
|
||||
#[cfg(not(feature = "gfx-backend-gl"))]
|
||||
impl Access<SurfaceHandle> for InstanceHandle {}
|
||||
impl Access<AdapterHandle> for Root {}
|
||||
impl Access<AdapterHandle> for SurfaceHandle {}
|
||||
@@ -195,6 +202,11 @@ thread_local! {
|
||||
static ACTIVE_TOKEN: Cell<bool> = Cell::new(false);
|
||||
}
|
||||
|
||||
/// A permission token to lock resource `T` or anything after it,
|
||||
/// as defined by the `Access` implementations.
|
||||
///
|
||||
/// Note: there can only be one non-borrowed `Token` alive on a thread
|
||||
/// at a time, which is enforced by `ACTIVE_TOKEN`.
|
||||
pub struct Token<'a, T: 'a> {
|
||||
level: PhantomData<&'a T>,
|
||||
is_root: bool,
|
||||
|
||||
@@ -207,15 +207,14 @@ pub fn instance_get_adapter(
|
||||
desc: &AdapterDescriptor,
|
||||
token: &mut Token<Root>,
|
||||
) -> AdapterHandle {
|
||||
let (instance_guard, mut token) = HUB.instances.read(token);
|
||||
#[cfg(not(feature = "gfx-backend-gl"))]
|
||||
let adapters = {
|
||||
let _ = &mut token;
|
||||
let (instance_guard, _) = HUB.instances.read(token);
|
||||
instance_guard[instance_id].enumerate_adapters()
|
||||
};
|
||||
#[cfg(feature = "gfx-backend-gl")]
|
||||
let adapters = {
|
||||
let (surface_guard, _) = HUB.surfaces.read(&mut token);
|
||||
let (surface_guard, _) = HUB.surfaces.read(token);
|
||||
surface_guard[instance_id].raw.enumerate_adapters()
|
||||
};
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ fn process(message: GlobalMessage) -> ControlFlow {
|
||||
wgn::HUB.instances.register(instance_id, instance, &mut token);
|
||||
}
|
||||
InstanceMessage::InstanceGetAdapter(instance_id, ref desc, id) => {
|
||||
let adapter = wgn::instance_get_adapter(instance_id, desc);
|
||||
let adapter = wgn::instance_get_adapter(instance_id, desc, &mut token);
|
||||
wgn::HUB.adapters.register(id, adapter, &mut token);
|
||||
}
|
||||
InstanceMessage::AdapterCreateDevice(adapter_id, ref desc, id) => {
|
||||
let device = wgn::adapter_create_device(adapter_id, desc);
|
||||
let device = wgn::adapter_create_device(adapter_id, desc, &mut token);
|
||||
wgn::HUB.devices.register(id, device, &mut token);
|
||||
}
|
||||
InstanceMessage::Destroy(instance_id) => {
|
||||
|
||||
Reference in new issue
Block a user