pub fn allocate(&self, size: usize, align: usize) -> *mut u8 {
        if align != *ALIGN { panic!("User requested alignment of {:?} but we only have {:?}", align, *ALIGN); }
        let ref mut header = unsafe { &(*self.header) };
        let mut offset : usize;
        loop { // attempt to fetch the next available slot, if it is taken, as evidenced by the CAS, then try again
            offset = header.current.load(Ordering::SeqCst);
            let newval = (((offset + size) - 1) | (*ALIGN - 1)) + 1;
            let oldval = header.current.compare_and_swap(offset, newval, Ordering::SeqCst);
            if offset == oldval { break }
        }
        if offset > self.total_size as usize {
            error!("we have gone past our allocated file space for the allocator : offset {:?}", offset);
            return unsafe { mem::transmute::<usize, *mut u8>(0)}
        }
        self.count.fetch_add(1, Ordering::SeqCst);
        unsafe { mem::transmute((self.addr as *mut u8).offset(offset as isize)) }
    }
//current is guaranteed to start off as aligned, so we'll ensure it stays that way
//get the current value to return, then calculate the next value to be supplied by
//the next call to this function
current is guaranteed to start off as aligned, so we'll ensure it stays that way
get the current value to return, then calculate the next value to be supplied by
the next call to this function
current is guaranteed to start off as aligned so we ' ll ensure it stays that way get the current value to return then calculate the next value to be supplied by the next call to this function
pub fn allocate(&self, size: usize, align: usize) -> *mut u8 {
        if align != *ALIGN { panic!("User requested alignment of {:?} but we only have {:?}", align, *ALIGN); }
        let ref mut header = unsafe { &(*self.header) };
        let mut offset : usize;
        loop { // attempt to fetch the next available slot, if it is taken, as evidenced by the CAS, then try again
            offset = header.current.load(Ordering::SeqCst);
            let newval = (((offset + size) - 1) | (*ALIGN - 1)) + 1;
            let oldval = header.current.compare_and_swap(offset, newval, Ordering::SeqCst);
            if offset == oldval { break }
        }
        if offset > self.total_size as usize {
            error!("we have gone past our allocated file space for the allocator : offset {:?}", offset);
            return unsafe { mem::transmute::<usize, *mut u8>(0)}
        }
        self.count.fetch_add(1, Ordering::SeqCst);
        unsafe { mem::transmute((self.addr as *mut u8).offset(offset as isize)) }
    }
pub fn allocate ( & self , size : usize , align : usize ) -> * mut u8 { if align != * ALIGN { panic ! ( " " align ALIGN ) ; } let ref mut header = unsafe { & ( * self . header ) } ; let mut offset : usize ; loop { // attempt to fetch the next available slot, if it is taken, as evidenced by the CAS, then try again offset = header . current . load ( Ordering :: SeqCst ) ; let newval = ( ( ( offset + size ) - 1 ) | ( * ALIGN - 1 ) ) + 1 ; let oldval = header . current . compare_and_swap ( offset , newval , Ordering :: SeqCst ) ; if offset == oldval { break } } if offset > self . total_size as usize { error ! ( " " offset ) ; return unsafe { mem :: transmute :: < usize , * mut u8 > ( 0 ) } } self . count . fetch_add ( 1 , Ordering :: SeqCst ) ; unsafe { mem :: transmute ( ( self . addr as * mut u8 ) . offset ( offset as isize ) ) } }
current is guaranteed to start off as aligned, so we'll ensure it stays that way
get the current value to return, then calculate the next value to be supplied by
the next call to this function
current is guaranteed to start off as aligned so we ' ll ensure it stays that way get the current value to return then calculate the next value to be supplied by the next call to this function
&self
size
usize
align
usize
&self
size
usize
align
usize