Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made fns in the impls for the Atomic structs pub #6941

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/libstd/unstable/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ pub enum Ordering {

impl AtomicFlag {

fn new() -> AtomicFlag {
pub fn new() -> AtomicFlag {
AtomicFlag { v: 0 }
}

/**
* Clears the atomic flag
*/
#[inline(always)]
fn clear(&mut self, order: Ordering) {
pub fn clear(&mut self, order: Ordering) {
unsafe {atomic_store(&mut self.v, 0, order)}
}

Expand All @@ -92,37 +92,37 @@ impl AtomicFlag {
* flag.
*/
#[inline(always)]
fn test_and_set(&mut self, order: Ordering) -> bool {
pub fn test_and_set(&mut self, order: Ordering) -> bool {
unsafe {atomic_compare_and_swap(&mut self.v, 0, 1, order) > 0}
}
}

impl AtomicBool {
fn new(v: bool) -> AtomicBool {
pub fn new(v: bool) -> AtomicBool {
AtomicBool { v: if v { 1 } else { 0 } }
}

#[inline(always)]
fn load(&self, order: Ordering) -> bool {
pub fn load(&self, order: Ordering) -> bool {
unsafe { atomic_load(&self.v, order) > 0 }
}

#[inline(always)]
fn store(&mut self, val: bool, order: Ordering) {
pub fn store(&mut self, val: bool, order: Ordering) {
let val = if val { 1 } else { 0 };

unsafe { atomic_store(&mut self.v, val, order); }
}

#[inline(always)]
fn swap(&mut self, val: bool, order: Ordering) -> bool {
pub fn swap(&mut self, val: bool, order: Ordering) -> bool {
let val = if val { 1 } else { 0 };

unsafe { atomic_swap(&mut self.v, val, order) > 0}
}

#[inline(always)]
fn compare_and_swap(&mut self, old: bool, new: bool, order: Ordering) -> bool {
pub fn compare_and_swap(&mut self, old: bool, new: bool, order: Ordering) -> bool {
let old = if old { 1 } else { 0 };
let new = if new { 1 } else { 0 };

Expand All @@ -131,113 +131,113 @@ impl AtomicBool {
}

impl AtomicInt {
fn new(v: int) -> AtomicInt {
pub fn new(v: int) -> AtomicInt {
AtomicInt { v:v }
}

#[inline(always)]
fn load(&self, order: Ordering) -> int {
pub fn load(&self, order: Ordering) -> int {
unsafe { atomic_load(&self.v, order) }
}

#[inline(always)]
fn store(&mut self, val: int, order: Ordering) {
pub fn store(&mut self, val: int, order: Ordering) {
unsafe { atomic_store(&mut self.v, val, order); }
}

#[inline(always)]
fn swap(&mut self, val: int, order: Ordering) -> int {
pub fn swap(&mut self, val: int, order: Ordering) -> int {
unsafe { atomic_swap(&mut self.v, val, order) }
}

#[inline(always)]
fn compare_and_swap(&mut self, old: int, new: int, order: Ordering) -> int {
pub fn compare_and_swap(&mut self, old: int, new: int, order: Ordering) -> int {
unsafe { atomic_compare_and_swap(&mut self.v, old, new, order) }
}

#[inline(always)]
fn fetch_add(&mut self, val: int, order: Ordering) -> int {
pub fn fetch_add(&mut self, val: int, order: Ordering) -> int {
unsafe { atomic_add(&mut self.v, val, order) }
}

#[inline(always)]
fn fetch_sub(&mut self, val: int, order: Ordering) -> int {
pub fn fetch_sub(&mut self, val: int, order: Ordering) -> int {
unsafe { atomic_sub(&mut self.v, val, order) }
}
}

impl AtomicUint {
fn new(v: uint) -> AtomicUint {
pub fn new(v: uint) -> AtomicUint {
AtomicUint { v:v }
}

#[inline(always)]
fn load(&self, order: Ordering) -> uint {
pub fn load(&self, order: Ordering) -> uint {
unsafe { atomic_load(&self.v, order) }
}

#[inline(always)]
fn store(&mut self, val: uint, order: Ordering) {
pub fn store(&mut self, val: uint, order: Ordering) {
unsafe { atomic_store(&mut self.v, val, order); }
}

#[inline(always)]
fn swap(&mut self, val: uint, order: Ordering) -> uint {
pub fn swap(&mut self, val: uint, order: Ordering) -> uint {
unsafe { atomic_swap(&mut self.v, val, order) }
}

#[inline(always)]
fn compare_and_swap(&mut self, old: uint, new: uint, order: Ordering) -> uint {
pub fn compare_and_swap(&mut self, old: uint, new: uint, order: Ordering) -> uint {
unsafe { atomic_compare_and_swap(&mut self.v, old, new, order) }
}

#[inline(always)]
fn fetch_add(&mut self, val: uint, order: Ordering) -> uint {
pub fn fetch_add(&mut self, val: uint, order: Ordering) -> uint {
unsafe { atomic_add(&mut self.v, val, order) }
}

#[inline(always)]
fn fetch_sub(&mut self, val: uint, order: Ordering) -> uint {
pub fn fetch_sub(&mut self, val: uint, order: Ordering) -> uint {
unsafe { atomic_sub(&mut self.v, val, order) }
}
}

impl<T> AtomicPtr<T> {
fn new(p: *mut T) -> AtomicPtr<T> {
pub fn new(p: *mut T) -> AtomicPtr<T> {
AtomicPtr { p:p }
}

#[inline(always)]
fn load(&self, order: Ordering) -> *mut T {
pub fn load(&self, order: Ordering) -> *mut T {
unsafe { atomic_load(&self.p, order) }
}

#[inline(always)]
fn store(&mut self, ptr: *mut T, order: Ordering) {
pub fn store(&mut self, ptr: *mut T, order: Ordering) {
unsafe { atomic_store(&mut self.p, ptr, order); }
}

#[inline(always)]
fn swap(&mut self, ptr: *mut T, order: Ordering) -> *mut T {
pub fn swap(&mut self, ptr: *mut T, order: Ordering) -> *mut T {
unsafe { atomic_swap(&mut self.p, ptr, order) }
}

#[inline(always)]
fn compare_and_swap(&mut self, old: *mut T, new: *mut T, order: Ordering) -> *mut T {
pub fn compare_and_swap(&mut self, old: *mut T, new: *mut T, order: Ordering) -> *mut T {
unsafe { atomic_compare_and_swap(&mut self.p, old, new, order) }
}
}

impl<T> AtomicOption<T> {
fn new(p: ~T) -> AtomicOption<T> {
pub fn new(p: ~T) -> AtomicOption<T> {
unsafe {
AtomicOption {
p: cast::transmute(p)
}
}
}

fn empty() -> AtomicOption<T> {
pub fn empty() -> AtomicOption<T> {
unsafe {
AtomicOption {
p: cast::transmute(0)
Expand All @@ -246,7 +246,7 @@ impl<T> AtomicOption<T> {
}

#[inline(always)]
fn swap(&mut self, val: ~T, order: Ordering) -> Option<~T> {
pub fn swap(&mut self, val: ~T, order: Ordering) -> Option<~T> {
unsafe {
let val = cast::transmute(val);

Expand All @@ -262,7 +262,7 @@ impl<T> AtomicOption<T> {
}

#[inline(always)]
fn take(&mut self, order: Ordering) -> Option<~T> {
pub fn take(&mut self, order: Ordering) -> Option<~T> {
unsafe {
self.swap(cast::transmute(0), order)
}
Expand Down