From 210ab8fb21efdb268cd11eac142bfdaa67cbe8ec Mon Sep 17 00:00:00 2001 From: i509VCB Date: Mon, 29 Nov 2021 12:18:05 -0600 Subject: [PATCH] allocator: general impls for Arc> and Rc> --- src/backend/allocator/mod.rs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/backend/allocator/mod.rs b/src/backend/allocator/mod.rs index 108f0bf..4f53369 100644 --- a/src/backend/allocator/mod.rs +++ b/src/backend/allocator/mod.rs @@ -22,6 +22,12 @@ pub mod dumb; pub mod gbm; mod swapchain; +use std::{ + cell::RefCell, + rc::Rc, + sync::{Arc, Mutex}, +}; + use crate::utils::{Buffer as BufferCoords, Size}; pub use swapchain::{Slot, Swapchain}; @@ -60,3 +66,34 @@ pub trait Allocator { modifiers: &[Modifier], ) -> Result; } + +// General implementations for interior mutability. + +impl, B: Buffer> Allocator for Arc> { + type Error = A::Error; + + fn create_buffer( + &mut self, + width: u32, + height: u32, + fourcc: Fourcc, + modifiers: &[Modifier], + ) -> Result { + let mut guard = self.lock().unwrap(); + guard.create_buffer(width, height, fourcc, modifiers) + } +} + +impl, B: Buffer> Allocator for Rc> { + type Error = A::Error; + + fn create_buffer( + &mut self, + width: u32, + height: u32, + fourcc: Fourcc, + modifiers: &[Modifier], + ) -> Result { + self.borrow_mut().create_buffer(width, height, fourcc, modifiers) + } +}