diff --git a/Cargo.toml b/Cargo.toml index 3c7bb871..583bd40b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ spinning_top = { version = "0.3.0", optional = true, public = true } pci_types = { version = "0.10.0", public = true } byteorder = { version = "1.5.0", optional = true, default-features = false } smallvec = { version = "1.15.2", optional = true, default-features = false, public = true } +static_assertions = "1.1.0" [dev-dependencies] aml-test-tools = { path = "tools/aml-test-tools" } @@ -30,7 +31,6 @@ lock_api = "0.4.14" parking_lot = "0.12.5" pretty_env_logger = "0.5.0" serial_test = "4.0.1" -static_assertions = "1.1.0" [features] default = ["alloc", "aml"] diff --git a/src/aml/mod.rs b/src/aml/mod.rs index a28ba497..e317f65d 100644 --- a/src/aml/mod.rs +++ b/src/aml/mod.rs @@ -133,10 +133,6 @@ pub type NoSendInterpreter = BaseInterpreter; /// An Interpreter that is known to be Send + Sync. The version you should prefer by default. pub type Interpreter = BaseInterpreter; -// TODO: Make sure to remove these two lines after Interpreter really is Send + Sync. -unsafe impl Send for Interpreter where H: Handler + Send {} -unsafe impl Sync for Interpreter where H: Handler + Send {} - /// The value returned by the `Revision` opcode. const INTERPRETER_REVISION: u64 = 1; diff --git a/src/aml/object.rs b/src/aml/object.rs index ebaca18b..7c788467 100644 --- a/src/aml/object.rs +++ b/src/aml/object.rs @@ -7,8 +7,9 @@ use alloc::{ }; use bit_field::BitField; use core::{cell::UnsafeCell, cmp::Ordering, fmt, ops, sync::atomic::AtomicU64}; +use static_assertions::assert_impl_all; -type NativeMethod = dyn Fn(&[WrappedObject]) -> Result; +type NativeMethod = dyn Fn(&[WrappedObject]) -> Result + Send + Sync; #[derive(Clone)] pub enum Object { @@ -37,7 +38,7 @@ pub enum Object { impl Object { pub fn native_method(num_args: u8, f: F) -> Object where - F: Fn(&[WrappedObject]) -> Result + 'static, + F: Fn(&[WrappedObject]) -> Result + 'static + Send + Sync, { let mut flags = 0; flags.set_bits(0..3, num_args); @@ -104,9 +105,15 @@ impl ObjectToken { } } +// In order for us to assert WrappedObject is Send + Sync, Object must be. +assert_impl_all!(Object: Send, Sync); + #[derive(Clone, Debug)] pub struct WrappedObject(Arc>); +unsafe impl Send for WrappedObject {} +unsafe impl Sync for WrappedObject {} + impl WrappedObject { pub fn new(object: Object) -> WrappedObject { #[allow(clippy::arc_with_non_send_sync)]