To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 327e1fdc authored by qinsoon's avatar qinsoon
Browse files

comment out Address.load_order()/store_order(). Issue #51

parent 953973c7
......@@ -16,7 +16,7 @@ use std;
use std::cmp;
use std::fmt;
use std::mem;
use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
//use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use std::ops::*;
use {ByteOffset, ByteSize};
......@@ -127,25 +127,28 @@ impl Address {
*(self.0 as *mut T)
}
/// loads a value of type T from the address with specified memory order
#[inline(always)]
pub unsafe fn load_order<T: Copy> (&self, order: Ordering) -> T {
let atomic_ptr : AtomicPtr<T> = mem::transmute(self.0);
*atomic_ptr.load(order)
}
/// stores a value of type T to the address
#[inline(always)]
pub unsafe fn store<T> (&self, value: T) {
*(self.0 as *mut T) = value;
}
/// stores a value of type T to the address with specified memory order
#[inline(always)]
pub unsafe fn store_order<T: Copy> (&self, mut value: T, order: Ordering) {
let atomic_ptr : AtomicPtr<T> = mem::transmute(self.0);
atomic_ptr.store(&mut value, order)
}
// commented out the function due to the fact that Rust does not have non-64bits atomic types
// Issue #51
// /// loads a value of type T from the address with specified memory order
// #[inline(always)]
// pub unsafe fn load_order<T: Copy> (&self, order: Ordering) -> T {
// let atomic_ptr : AtomicPtr<T> = mem::transmute(self.0);
// *atomic_ptr.load(order)
// }
// /// stores a value of type T to the address with specified memory order
// #[inline(always)]
// pub unsafe fn store_order<T: Copy> (&self, mut value: T, order: Ordering) {
// let atomic_ptr : AtomicPtr<T> = mem::transmute(self.0);
// atomic_ptr.store(&mut value, order)
// }
/// is this address zero?
#[inline(always)]
......
use utils::Address;
use std::sync::atomic::Ordering;
//use std::sync::atomic::Ordering;
#[test]
fn test_align_up() {
......@@ -26,107 +26,102 @@ fn test_is_aligned() {
assert!(addr.is_aligned_to(8));
}
#[ignore]
#[test]
fn test_load_order_u64() {
let mem = Box::new(42u64);
let ptr = Box::into_raw(mem);
let addr = Address::from_mut_ptr(ptr);
unsafe {
let value_relaxed : u64 = addr.load_order(Ordering::Relaxed);
assert_eq!(value_relaxed, 42);
let value_seqcst : u64 = addr.load_order(Ordering::SeqCst);
assert_eq!(value_seqcst, 42);
let value_acquire : u64 = addr.load_order(Ordering::Acquire);
assert_eq!(value_acquire, 42);
}
}
#[ignore]
#[test]
fn test_store_order_u64() {
let mem = Box::new(0u64);
let ptr = Box::into_raw(mem);
let addr = Address::from_mut_ptr(ptr);
unsafe {
let expect : u64 = 42;
addr.store_order(expect, Ordering::Relaxed);
let val : u64 = addr.load();
assert_eq!(val, expect);
let expect : u64 = 21;
addr.store_order(expect, Ordering::Release);
let val : u64 = addr.load();
assert_eq!(val, expect);
let expect : u64 = 10;
addr.store_order(expect, Ordering::SeqCst);
let val : u64 = addr.load();
assert_eq!(val, expect);
}
}
#[ignore]
#[test]
fn test_load_order_u32() {
let mem = Box::new(-1isize);
let ptr = Box::into_raw(mem);
let addr = Address::from_mut_ptr(ptr);
unsafe {
addr.store(42u32);
let value_relaxed : u32 = addr.load_order(Ordering::Relaxed);
assert_eq!(value_relaxed, 42);
let value_seqcst : u32 = addr.load_order(Ordering::SeqCst);
assert_eq!(value_seqcst, 42);
let value_acquire : u32 = addr.load_order(Ordering::Acquire);
assert_eq!(value_acquire, 42);
}
}
#[ignore]
#[test]
fn test_load_order_f64() {
let mem = Box::new(42.0f64);
let ptr = Box::into_raw(mem);
let addr = Address::from_mut_ptr(ptr);
unsafe {
let value_relaxed : f64 = addr.load_order(Ordering::Relaxed);
assert_eq!(value_relaxed, 42f64);
let value_seqcst : f64 = addr.load_order(Ordering::SeqCst);
assert_eq!(value_seqcst, 42f64);
let value_acquire : f64 = addr.load_order(Ordering::Acquire);
assert_eq!(value_acquire, 42f64);
}
}
#[ignore]
#[test]
fn test_load_order_f32() {
let mem = Box::new(42.0f64);
let ptr = Box::into_raw(mem);
let addr = Address::from_mut_ptr(ptr);
unsafe {
addr.store(10f32);
let value_relaxed : f32 = addr.load_order(Ordering::Relaxed);
assert_eq!(value_relaxed, 10f32);
let value_seqcst : f32 = addr.load_order(Ordering::SeqCst);
assert_eq!(value_seqcst, 10f32);
let value_acquire : f32 = addr.load_order(Ordering::Acquire);
assert_eq!(value_acquire, 10f32);
}
}
\ No newline at end of file
//#[test]
//fn test_load_order_u64() {
// let mem = Box::new(42u64);
// let ptr = Box::into_raw(mem);
// let addr = Address::from_mut_ptr(ptr);
//
// unsafe {
// let value_relaxed : u64 = addr.load_order(Ordering::Relaxed);
// assert_eq!(value_relaxed, 42);
//
// let value_seqcst : u64 = addr.load_order(Ordering::SeqCst);
// assert_eq!(value_seqcst, 42);
//
// let value_acquire : u64 = addr.load_order(Ordering::Acquire);
// assert_eq!(value_acquire, 42);
// }
//}
//
//#[test]
//fn test_store_order_u64() {
// let mem = Box::new(0u64);
// let ptr = Box::into_raw(mem);
// let addr = Address::from_mut_ptr(ptr);
//
// unsafe {
// let expect : u64 = 42;
// addr.store_order(expect, Ordering::Relaxed);
// let val : u64 = addr.load();
// assert_eq!(val, expect);
//
// let expect : u64 = 21;
// addr.store_order(expect, Ordering::Release);
// let val : u64 = addr.load();
// assert_eq!(val, expect);
//
// let expect : u64 = 10;
// addr.store_order(expect, Ordering::SeqCst);
// let val : u64 = addr.load();
// assert_eq!(val, expect);
// }
//}
//
//#[test]
//fn test_load_order_u32() {
// let mem = Box::new(-1isize);
// let ptr = Box::into_raw(mem);
// let addr = Address::from_mut_ptr(ptr);
//
// unsafe {
// addr.store(42u32);
//
// let value_relaxed : u32 = addr.load_order(Ordering::Relaxed);
// assert_eq!(value_relaxed, 42);
//
// let value_seqcst : u32 = addr.load_order(Ordering::SeqCst);
// assert_eq!(value_seqcst, 42);
//
// let value_acquire : u32 = addr.load_order(Ordering::Acquire);
// assert_eq!(value_acquire, 42);
// }
//}
//
//#[test]
//fn test_load_order_f64() {
// let mem = Box::new(42.0f64);
// let ptr = Box::into_raw(mem);
// let addr = Address::from_mut_ptr(ptr);
//
// unsafe {
// let value_relaxed : f64 = addr.load_order(Ordering::Relaxed);
// assert_eq!(value_relaxed, 42f64);
//
// let value_seqcst : f64 = addr.load_order(Ordering::SeqCst);
// assert_eq!(value_seqcst, 42f64);
//
// let value_acquire : f64 = addr.load_order(Ordering::Acquire);
// assert_eq!(value_acquire, 42f64);
// }
//}
//
//#[test]
//fn test_load_order_f32() {
// let mem = Box::new(42.0f64);
// let ptr = Box::into_raw(mem);
// let addr = Address::from_mut_ptr(ptr);
//
// unsafe {
// addr.store(10f32);
//
// let value_relaxed : f32 = addr.load_order(Ordering::Relaxed);
// assert_eq!(value_relaxed, 10f32);
//
// let value_seqcst : f32 = addr.load_order(Ordering::SeqCst);
// assert_eq!(value_seqcst, 10f32);
//
// let value_acquire : f32 = addr.load_order(Ordering::Acquire);
// assert_eq!(value_acquire, 10f32);
// }
//}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment