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

Move to 2024-05-18 nightly #6

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ memmap = "0.7.0"
term-painter = "0.3.0"
libc = "0.2.82"
impl-trait-for-tuples = "0.2.0"
crndm_derive = "0.1.1"
crndm_derive = { path="./crndm_derive"}
num_cpus = "1.13.0"

# examples
Expand Down
8 changes: 4 additions & 4 deletions crndm_derive/src/cbinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::spanned::Spanned;
use syn::*;
use syn::punctuated::Punctuated;
use std::collections::HashMap;
use std::lazy::SyncLazy;
use std::sync::LazyLock;
use std::sync::Mutex;
use std::io::*;
use std::fs::{File,create_dir_all,read_to_string};
Expand Down Expand Up @@ -36,11 +36,11 @@ pub struct Attributes {
concurrent: bool
}

pub static mut TYPES: SyncLazy<Mutex<HashMap<TypeName, Contents>>> = SyncLazy::new(|| {
pub static mut TYPES: LazyLock<Mutex<HashMap<TypeName, Contents>>> = LazyLock::new(|| {
Mutex::new(HashMap::new())
});

pub static mut POOLS: SyncLazy<Mutex<HashMap<TypeName, Contents>>> = SyncLazy::new(|| {
pub static mut POOLS: LazyLock<Mutex<HashMap<TypeName, Contents>>> = LazyLock::new(|| {
Mutex::new(HashMap::new())
});

Expand Down Expand Up @@ -280,7 +280,7 @@ pub fn derive_cbindgen(input: TokenStream) -> TokenStream {
Ok(g) => g,
Err(p) => p.into_inner()
} };
let mut entry = all_types.entry(name_str.clone()).or_insert(Contents::default());
let entry = all_types.entry(name_str.clone()).or_insert(Contents::default());
entry.generics = generics.iter().map(|v| v.to_string()).collect();
let new_sizes: Vec<Ident> = generics.iter().map(|v| format_ident!("{}_size", v.to_string())).collect();

Expand Down
2 changes: 0 additions & 2 deletions crndm_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(once_cell)]
#![feature(type_name_of_val)]
#![feature(proc_macro_span)]

use proc_macro2::Group;
Expand Down
3 changes: 0 additions & 3 deletions examples/mapcli/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ mod vbtree;

pub use btree::*;
pub use ctree::*;
pub use pbtree::*;
pub use rbtree::*;
pub use rtree::*;
pub use ubtree::*;
pub use vbtree::*;

use corundum::default::*;

Expand Down
22 changes: 11 additions & 11 deletions examples/mapcli/map/rtree.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::map::Map;
use corundum::default::*;

use std::collections::BTreeMap;
use std::{cell::UnsafeCell, collections::BTreeMap};

type P = Allocator;

pub struct RTree<K, V> {
btree: BTreeMap<K, V>,
btree: UnsafeCell<BTreeMap<K, V>>,
}

impl<K, V> RTree<K, V> {
fn self_mut(&self) -> &mut Self {
unsafe { &mut *(self as *const Self as *mut Self) }
fn get(&self) -> &mut BTreeMap<K, V> {
unsafe { &mut *self.btree.get() }
}
}

Expand All @@ -20,32 +20,32 @@ where
K: std::cmp::Ord,
{
fn clear(&self) {
self.self_mut().btree.clear();
self.get().clear();
}
fn insert(&self, key: K, val: V) {
self.self_mut().btree.insert(key, val);
self.get().insert(key, val);
}
fn remove(&self, key: K) {
self.self_mut().btree.remove(&key);
self.get().remove(&key);
}
fn is_empty(&self) -> bool {
self.btree.is_empty()
self.get().is_empty()
}
fn foreach<F: Copy + Fn(&K, &V) -> bool>(&self, f: F) -> bool {
for (k, v) in &self.btree {
for (k, v) in self.get() {
f(k, v);
}
true
}
fn lookup(&self, key: K) -> bool {
self.btree.get(&key).is_some()
self.get().get(&key).is_some()
}
}

impl<K: std::cmp::Ord, V> Default for RTree<K, V> {
fn default() -> Self {
Self {
btree: BTreeMap::new(),
btree: UnsafeCell::new(BTreeMap::new()),
}
}
}
5 changes: 3 additions & 2 deletions examples/microbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod run {
use corundum::stat::*;
use corundum::open_flags::*;
use corundum::stm::{Log, Logger, Notifier};
use std::arch::asm;

type P = Allocator;
const CNT: usize = 50000;
Expand All @@ -28,7 +29,7 @@ mod run {
};
}

fn main() {
pub fn main() {
use std::env;
use std::vec::Vec as StdVec;

Expand Down Expand Up @@ -282,7 +283,7 @@ mod run {
let layout = std::alloc::Layout::from_size_align(*s * 8, 4).unwrap();
measure!(format!("malloc({})", *s * 8), cnt, {
for _ in 0..cnt {
unsafe{ std::alloc::alloc(layout); }
unsafe{ let _ = std::alloc::alloc(layout); }
}
});
}
Expand Down
1 change: 0 additions & 1 deletion examples/simplekv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#![allow(dead_code)]
#![allow(incomplete_features)]
#![feature(type_name_of_val)]

use std::mem::MaybeUninit;
use corundum::default::*;
Expand Down
8 changes: 5 additions & 3 deletions src/alloc/alg/buddy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::ops::{Index,IndexMut};
use std::marker::PhantomData;
use std::mem;


#[repr(transparent)]
#[derive(Clone, Debug)]
/// Buddy memory block
Expand Down Expand Up @@ -176,7 +177,7 @@ impl<A: MemPool> BuddyAlg<A> {

#[cfg(any(feature = "no_pthread", windows))] {
let tid = std::thread::current().id().as_u64().get();
while std::intrinsics::atomic_cxchg_acqrel(&mut self.mutex, 0, tid).0 != tid {}
while std::intrinsics::atomic_cxchg_acqrel_acquire(&mut self.mutex, 0, tid).0 != tid {}
}
}
}
Expand All @@ -188,7 +189,7 @@ impl<A: MemPool> BuddyAlg<A> {
libc::pthread_mutex_unlock(&mut self.mutex.0);

#[cfg(any(feature = "no_pthread", windows))]
std::intrinsics::atomic_store_rel(&mut self.mutex, 0);
std::intrinsics::atomic_store_release(&mut self.mutex, 0);
}
}

Expand Down Expand Up @@ -232,7 +233,7 @@ impl<A: MemPool> BuddyAlg<A> {
self.aux.clear();
self.log64.foreach(|(off, data)| unsafe {
let n = Self::buddy(off);
std::intrinsics::atomic_store_rel(&mut n.next, data);
std::intrinsics::atomic_store_release(&mut n.next, data);
});
self.log64.clear();
self.available = self.available_log;
Expand Down Expand Up @@ -1003,6 +1004,7 @@ macro_rules! pool {
($mod:ident, $name:ident) => {
/// The default allocator module
pub mod $mod {
#![allow(unused_imports)]
use memmap::*;
use std::collections::hash_map::DefaultHasher;
use std::collections::{HashMap,HashSet};
Expand Down
2 changes: 1 addition & 1 deletion src/alloc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ unsafe impl MemPoolTraits for Heap {

unsafe fn journals_head() -> &'static u64 {
static mut HEAD: u64 = u64::MAX;
&HEAD
&*std::ptr::addr_of!(HEAD)
}

unsafe fn close() -> Result<()> {
Expand Down
5 changes: 0 additions & 5 deletions src/cell/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ impl<T: PSafe, A: MemPool> PCell<T, A> {
self.value.into_inner().1
}
}

#[inline]
fn self_mut(&self) -> &mut Self {
unsafe { &mut *(self as *const Self as *mut Self) }
}
}

impl<T: PSafe, A: MemPool> PCell<T, A> {
Expand Down
11 changes: 1 addition & 10 deletions src/cell/refcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,6 @@ impl<T: PSafe + Debug + ?Sized, A: MemPool> Debug for PRefCell<T, A> {
}

impl<T: PSafe + ?Sized, A: MemPool> PRefCell<T, A> {
#[inline(always)]
#[allow(clippy::mut_from_ref)]
fn self_mut(&self) -> &mut Self {
unsafe {
let ptr: *const Self = self;
&mut *(ptr as *mut Self)
}
}

#[inline]
#[allow(clippy::mut_from_ref)]
/// Takes a log and returns a mutable reference to the underlying data.
Expand Down Expand Up @@ -476,7 +467,7 @@ impl<T: PSafe, A: MemPool> PRefCell<T, A> {
*borrow = 1;
}
RefMut {
value: unsafe { &mut *(self as *const Self as *mut Self) },
value: self as *const Self as *mut Self,
journal,
phantom: PhantomData
}
Expand Down
2 changes: 1 addition & 1 deletion src/cell/tcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<T: Default + VSafe, A: MemPool> TCell<T, A> {

#[inline]
pub(crate) fn as_mut(&self) -> &mut T {
unsafe { &mut *(self.deref() as *const T as *mut T) }
unsafe { utils::as_mut(self).force() }
}

#[inline]
Expand Down
Loading