pub fn acquire_bit(&self) -> Option<usize> {
        for (index, byte) in self.slice.iter().enumerate() {
            let mut acquired_bit = None;

            // We don't care about success/failure because that's
            // actually captured by acquired_bit.
            //
            // We shouldn't need to order other memory - we are just
            // concerned with this byte - so Relaxed is appropriate.
            let _ = byte.fetch_update(Relaxed, Relaxed, |val| {
                for bit in 0..8 {
                    if val & (1 << bit) == 0 {
                        // We may have acquired it, but this can run
                        // again if we fail to CAS.
                        acquired_bit = Some(bit);
                        return Some(val | (1 << bit));
                    }
                }
                // Don't change.
                acquired_bit = None;
                None
            });

            if let Some(bit) = acquired_bit {
                return Some(index * 8 + bit);
            }
        }

        // None of the bytes had a free value
        None
    }
/// Atomically finds the first free bit and sets it to used, then
/// returns the index of the acquired bit.
Atomically finds the first free bit and sets it to used, then
returns the index of the acquired bit.
Atomically finds the first free bit and sets it to used then returns the index of the acquired bit .
pub fn acquire_bit(&self) -> Option<usize> {
        for (index, byte) in self.slice.iter().enumerate() {
            let mut acquired_bit = None;
            // We don't care about success/failure because that's
            // actually captured by acquired_bit.
            //
            // We shouldn't need to order other memory - we are just
            // concerned with this byte - so Relaxed is appropriate.
            let _ = byte.fetch_update(Relaxed, Relaxed, |val| {
                for bit in 0..8 {
                    if val & (1 << bit) == 0 {
                        // We may have acquired it, but this can run
                        // again if we fail to CAS.
                        acquired_bit = Some(bit);
                        return Some(val | (1 << bit));
                    }
                }
                // Don't change.
                acquired_bit = None;
                None
            });
            if let Some(bit) = acquired_bit {
                return Some(index * 8 + bit);
            }
        }
        // None of the bytes had a free value
        None
    }
pub fn acquire_bit ( & self ) -> Option < usize > { for ( index , byte ) in self . slice . iter ( ) . enumerate ( ) { let mut acquired_bit = None ; // We don't care about success/failure because that's // actually captured by acquired_bit. // // We shouldn't need to order other memory - we are just // concerned with this byte - so Relaxed is appropriate. let _ = byte . fetch_update ( Relaxed , Relaxed , | val | { for bit in 0 .. 8 { if val & ( 1 << bit ) == 0 { // We may have acquired it, but this can run // again if we fail to CAS. acquired_bit = Some ( bit ) ; return Some ( val | ( 1 << bit ) ) ; } } // Don't change. acquired_bit = None ; None } ) ; if let Some ( bit ) = acquired_bit { return Some ( index * 8 + bit ) ; } } // None of the bytes had a free value None }
Atomically finds the first free bit and sets it to used, then
returns the index of the acquired bit.
Atomically finds the first free bit and sets it to used then returns the index of the acquired bit .
&self