From b60ad061346d4168dd6ae0ae80158cf0c141645e Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 16 Sep 2022 01:46:15 +0800 Subject: [PATCH] add a clone function for AtomicCsr this is useful for the performance profiling framework where we want to stick the allocatde CSRs into structures that help manage things. --- svd2utra/src/generate.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/svd2utra/src/generate.rs b/svd2utra/src/generate.rs index c1543f42d..1ffa5e492 100644 --- a/svd2utra/src/generate.rs +++ b/svd2utra/src/generate.rs @@ -655,6 +655,17 @@ where base: AtomicPtr::new(base) } } + /// In reality, we should wrap this in an `Arc` so we can be truly safe across a multi-core + /// implementation, but for our single-core system this is fine. The reason we don't do it + /// immediately is that UTRA also needs to work in a `no_std` environment, where `Arc` + /// does not exist, and so additional config flags would need to be introduced to not break + /// that compability issue. If migrating to multicore, this technical debt would have to be + /// addressed. + pub fn clone(&self) -> Self { + AtomicCsr { + base: AtomicPtr::new(self.base.load(core::sync::atomic::Ordering::SeqCst)) + } + } /// Read the contents of this register pub fn r(&self, reg: Register) -> T { // prevent re-ordering