Skip to content

Commit

Permalink
Merge #689
Browse files Browse the repository at this point in the history
689: Replace wasmer_runtime_code::memory::Atomic with std::sync::atomic atomics. r=nlewycky a=nlewycky

This means we lose op_new(), op_weak() and proxy() from the interface.

Co-authored-by: Nick Lewycky <[email protected]>
Co-authored-by: nlewycky <[email protected]>
  • Loading branch information
bors[bot] and nlewycky authored Aug 17, 2019
2 parents 0a3182e + 8b22d40 commit dac86ee
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 274 deletions.
263 changes: 0 additions & 263 deletions lib/runtime-core/src/memory/atomic.rs

This file was deleted.

2 changes: 0 additions & 2 deletions lib/runtime-core/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ use std::{
rc::Rc,
};

pub use self::atomic::Atomic;
pub use self::dynamic::DynamicMemory;
pub use self::static_::{SharedStaticMemory, StaticMemory};
pub use self::view::{Atomically, MemoryView};

mod atomic;
mod dynamic;
pub mod ptr;
mod static_;
Expand Down
52 changes: 44 additions & 8 deletions lib/runtime-core/src/memory/view.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
use super::atomic::{Atomic, IntCast};
use crate::types::ValueType;

use std::sync::atomic::{
AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicU16, AtomicU32, AtomicU64, AtomicU8,
};
use std::{cell::Cell, marker::PhantomData, ops::Deref, slice};

pub trait Atomic {
type Output;
}
impl Atomic for i8 {
type Output = AtomicI8;
}
impl Atomic for i16 {
type Output = AtomicI16;
}
impl Atomic for i32 {
type Output = AtomicI32;
}
impl Atomic for i64 {
type Output = AtomicI64;
}
impl Atomic for u8 {
type Output = AtomicU8;
}
impl Atomic for u16 {
type Output = AtomicU16;
}
impl Atomic for u32 {
type Output = AtomicU32;
}
impl Atomic for u64 {
type Output = AtomicU64;
}
impl Atomic for f32 {
type Output = AtomicU32;
}
impl Atomic for f64 {
type Output = AtomicU64;
}

pub trait Atomicity {}
pub struct Atomically;
impl Atomicity for Atomically {}
Expand All @@ -28,10 +64,10 @@ where
}
}

impl<'a, T: IntCast> MemoryView<'a, T, NonAtomically> {
pub fn atomically(&self) -> MemoryView<'a, T, Atomically> {
impl<'a, T: Atomic> MemoryView<'a, T> {
pub fn atomically(&self) -> MemoryView<'a, T::Output, Atomically> {
MemoryView {
ptr: self.ptr,
ptr: self.ptr as *mut T::Output,
length: self.length,
_phantom: PhantomData,
}
Expand All @@ -45,9 +81,9 @@ impl<'a, T> Deref for MemoryView<'a, T, NonAtomically> {
}
}

impl<'a, T: IntCast> Deref for MemoryView<'a, T, Atomically> {
type Target = [Atomic<T>];
fn deref(&self) -> &[Atomic<T>] {
unsafe { slice::from_raw_parts(self.ptr as *const Atomic<T>, self.length) }
impl<'a, T> Deref for MemoryView<'a, T, Atomically> {
type Target = [T];
fn deref(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.ptr as *const T, self.length) }
}
}
2 changes: 1 addition & 1 deletion lib/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub use wasmer_runtime_core::{compile_with, validate};
pub use wasmer_runtime_core::{func, imports};

pub mod memory {
pub use wasmer_runtime_core::memory::{Atomic, Atomically, Memory, MemoryView};
pub use wasmer_runtime_core::memory::{Atomically, Memory, MemoryView};
}

pub mod wasm {
Expand Down

0 comments on commit dac86ee

Please sign in to comment.