Skip to content

Commit

Permalink
remove some more guards. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
density215 committed Oct 23, 2024
1 parent 4b094d9 commit 7e9c634
Show file tree
Hide file tree
Showing 14 changed files with 630 additions and 613 deletions.
36 changes: 16 additions & 20 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use ansi_term::Colour;
use rustyline::error::ReadlineError;
use rustyline::Editor;

use rotonda_store::prelude::{*, multi::*};
use rotonda_store::meta_examples::PrefixAs;
use inetnum::addr::Prefix;
use rotonda_store::meta_examples::PrefixAs;
use rotonda_store::prelude::{multi::*, *};
use rustyline::history::DefaultHistory;

use std::env;
Expand All @@ -14,7 +14,6 @@ use std::ffi::OsString;
use std::fs::File;
use std::process;


fn get_first_arg() -> Result<OsString, Box<dyn Error>> {
match env::args_os().nth(1) {
None => Err(From::from("expected 1 argument, but got none")),
Expand Down Expand Up @@ -100,28 +99,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match cmd.to_string().as_ref() {
"p" => match line.chars().as_str() {
"p4" => {
tree_bitmap
.prefixes_iter_v4(guard)
.for_each(|pfx| {
tree_bitmap.prefixes_iter_v4().for_each(
|pfx| {
println!(
"{} {}",
pfx.prefix, pfx.meta[0]
);
});
},
);
println!(
"ipv4 prefixes :\t{}",
tree_bitmap.prefixes_v4_count()
);
}
"p6" => {
tree_bitmap
.prefixes_iter_v6(guard)
.for_each(|pfx| {
tree_bitmap.prefixes_iter_v6().for_each(
|pfx| {
println!(
"{} {}",
pfx.prefix, pfx.meta[0]
);
});
},
);
println!(
"ipv6 prefixes :\t{}",
tree_bitmap.prefixes_v6_count()
Expand All @@ -136,14 +135,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"ipv6 prefixes :\t{}",
tree_bitmap.prefixes_v6_count()
);
tree_bitmap
.prefixes_iter(guard)
.for_each(|pfx| {
tree_bitmap.prefixes_iter().for_each(
|pfx| {
println!(
"{} {}",
pfx.prefix, pfx.meta[0]
);
});
},
);
println!(
"total prefixes :\t{}",
tree_bitmap.prefixes_count()
Expand Down Expand Up @@ -275,17 +274,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.to_string())
);
}
Err(
inetnum::addr::PrefixError::NonZeroHost,
) => {
Err(inetnum::addr::PrefixError::NonZeroHost) => {
println!("{}", Colour::Yellow.paint("Warning: Prefix has bits set to the right of the prefix length. Zeroing those out."));
println!(
"{}",
tree_bitmap.match_prefix(
&Prefix::new_relaxed(ip, len)?,
&MatchOptions {
match_type:
MatchType::ExactMatch,
match_type: MatchType::ExactMatch,
include_withdrawn: true,
include_less_specifics: true,
include_more_specifics: true,
Expand Down
21 changes: 21 additions & 0 deletions src/local_array/atomic_stride.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ where
fn load(&self) -> Self::InnerType;
fn to_u64(&self) -> u64;
fn to_u32(&self) -> u32;
fn set(&self, value: Self::InnerType);
fn merge_with(&self, node: Self::InnerType) {
let mut spinwait = SpinWait::new();
let current = self.load();
Expand Down Expand Up @@ -99,6 +100,10 @@ impl AtomicBitmap for AtomicStride2 {
self.0.load(Ordering::SeqCst)
}

fn set(&self, value: Self::InnerType) {
self.0.store(value, Ordering::Relaxed);
}

fn to_u32(&self) -> u32 {
self.0.load(Ordering::SeqCst) as u32
}
Expand Down Expand Up @@ -153,6 +158,10 @@ impl AtomicBitmap for AtomicStride3 {
self.0.load(Ordering::Relaxed)
}

fn set(&self, value: Self::InnerType) {
self.0.store(value, Ordering::Relaxed);
}

fn to_u32(&self) -> u32 {
self.0.load(Ordering::Relaxed) as u32
}
Expand Down Expand Up @@ -206,6 +215,10 @@ impl AtomicBitmap for AtomicStride4 {
self.0.load(Ordering::Relaxed)
}

fn set(&self, value: Self::InnerType) {
self.0.store(value, Ordering::Relaxed);
}

fn to_u32(&self) -> u32 {
self.0.load(Ordering::Relaxed)
}
Expand Down Expand Up @@ -258,6 +271,10 @@ impl AtomicBitmap for AtomicStride5 {
self.0.load(Ordering::SeqCst)
}

fn set(&self, value: Self::InnerType) {
self.0.store(value, Ordering::Relaxed);
}

fn to_u32(&self) -> u32 {
self.0.load(Ordering::SeqCst) as u32
}
Expand Down Expand Up @@ -335,6 +352,10 @@ impl AtomicBitmap for AtomicStride6 {
])
}

fn set(&self, _value: Self::InnerType) {
todo!()
}

fn to_u32(&self) -> u32 {
unimplemented!()
}
Expand Down
15 changes: 7 additions & 8 deletions src/local_array/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
marker::PhantomData,
};

use crossbeam_utils::Backoff;
use log::trace;
use parking_lot_core::SpinWait;

// pub use super::atomic_stride::*;
use super::bit_span::BitSpan;
Expand Down Expand Up @@ -198,7 +198,8 @@ where

// We are not at the last stride
// Check it the ptr bit is already set in this position
if (S::into_stride_size(ptrbitarr) & bit_pos) == <<<S as Stride>::AtomicPfxSize as AtomicBitmap>::InnerType>::zero() {
if (S::into_stride_size(ptrbitarr) & bit_pos) ==
<<<S as Stride>::AtomicPfxSize as AtomicBitmap>::InnerType>::zero() {
// Nope, set it and create a child node

match next_stride.unwrap() {
Expand Down Expand Up @@ -231,8 +232,6 @@ where
}
};



// THE CRITICAL SECTION
//
// UPDATING pfxbitarr
Expand All @@ -243,7 +242,7 @@ where
S::into_ptrbitarr_size(
bit_pos | S::into_stride_size(ptrbitarr),
));
let backoff = Backoff::new();
let mut spinwait = SpinWait::new();
loop {
match a_ptrbitarr {
CasResult(Ok(_)) => {
Expand All @@ -259,7 +258,7 @@ where
));
}
};
backoff.spin();
spinwait.spin_no_yield();
}

return (NewNodeOrIndex::NewNode(
Expand All @@ -283,7 +282,7 @@ where
self.pfxbitarr.compare_exchange(
pfxbitarr, bit_pos | pfxbitarr
);
let backoff = Backoff::new();
let mut spinwait = SpinWait::new();

loop {
match a_pfxbitarr {
Expand All @@ -299,7 +298,7 @@ where
);
}
};
backoff.spin();
spinwait.spin_no_yield();
}

return (NewNodeOrIndex::NewPrefix, retry_count);
Expand Down
2 changes: 1 addition & 1 deletion src/local_array/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ where
&'a self,
search_pfx: PrefixId<AF>,
options: &MatchOptions,
guard: &'a Guard,
// guard: &'a Guard,
) -> QueryResult<M> {
// --- The Default Route Prefix -------------------------------------

Expand Down
Loading

0 comments on commit 7e9c634

Please sign in to comment.