Skip to content

Make WrappedObject Send + Sync using RwLock#307

Open
martin-hughes wants to merge 1 commit into
rust-osdev:mainfrom
martin-hughes:rw_lock-object
Open

Make WrappedObject Send + Sync using RwLock#307
martin-hughes wants to merge 1 commit into
rust-osdev:mainfrom
martin-hughes:rw_lock-object

Conversation

@martin-hughes

Copy link
Copy Markdown
Contributor

This PR is inspired by the same reason I asked #302 - I'd like to be much more sure acpi is actually safe. It's a suggestion really, to see if you like it @IsaacWoods. Thoughts?

There are, IMO, at least a couple of things I don't like about WrappedObject.

  1. It is currently very easy to use WrappedObject in an unsafe way despite the unsafe impl statements, and
  2. The deref behaviour isn't totally intuitive and I think using the inner object benefits from being more explicit.

So with that in mind I've generated this PR.

I'm not sure if you have any feelings about AI generated code @IsaacWoods so for full disclosure - the heavy lifting here was done by Claude's Opus 4.8 model based on my prompts and questions.

I've then refined, reviewed, edited and tested it - no vibe coding here! But I can imagine you might think of a better way to achieve the same goal, in which case I'm happy to make a second attempt.

This changes the WrappedObject interface, so will need a version bump.

The aim is to remove the unsafe Send and Sync implementations, to:

- Make sure WrappedObject really is Send / Sync
- Make it easier for users to use WrappedObject in a thread-safe way.
use acpi::aml::{Interpreter, object::WrappedObject};
use static_assertions::assert_impl_all;

assert_impl_all!(Interpreter<NullHandler>: Send, Sync);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed I hadn't taken this line out - it'll always be true, as it stands (due to the unsafe impl blocks).

Reason it's here is that I've been experimenting with how to remove those unsafe impl blocks from Interpreter - my feeling is they make it too easy to make other mistakes (such as in #306 where the allocator may not be Send + Sync) but I haven't got all the way there yet.

I'll try and remember to take out that test with any updates you want me to make.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant