rust-osdev / volatile

Apache License 2.0
70 stars 19 forks source link

Idea: Provide atomic volatile types #30

Closed phil-opp closed 1 year ago

phil-opp commented 1 year ago

Proposed by @mkroening in https://github.com/rust-osdev/volatile/pull/29#issuecomment-1398132992.

mkroening commented 1 year ago

My initial thought was on using AtomicPtr to atomically move the pointer between cores. This would model Option<&mut T> or Option<AtomicPtrSend>. Thinking about it, I can't find much use for that over a SpinMutex<AtomicPtrSend>, though.

Using atomic types for MMIO data would have the existing issue regarding references and dereferencable. One could use intrinsics like core::intrinsics::atomic_load_relaxed, but intrinsics are never intended to be stabilized.

phil-opp commented 1 year ago

Ah, thanks for clarifying! In that case, let's postpone this idea for now untl a potential use-case comes up.

Using atomic types for MMIO data would have the existing issue regarding references and dereferencable. One could use intrinsics like core::intrinsics::atomic_load_relaxed, but intrinsics are never intended to be stabilized.

Yeah, good point.

Freax13 commented 1 year ago

Related: https://github.com/rust-lang/unsafe-code-guidelines/issues/347

phil-opp commented 1 year ago

Also related: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/volatile.20atomic.20in.20Rust.3F