Add sync module

next
Sayan Nandan 2 years ago
parent 27e462fb4f
commit 44aa57a25a
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

522
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -19,6 +19,7 @@ env_logger = "0.9.0"
hashbrown = { version = "0.12.3", features = ["raw"] }
log = "0.4.17"
openssl = { version = "0.10.41", features = ["vendored"] }
crossbeam-epoch = "0.9.13"
parking_lot = "0.12.1"
regex = "1.6.0"
serde = { version = "1.0.144", features = ["derive"] }

@ -24,32 +24,6 @@
*
*/
/*
* Created on Wed Jan 11 2023
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use core::{borrow::Borrow, hash::Hash};
mod stseq;

@ -32,3 +32,4 @@ mod macros;
mod core;
mod idx;
mod ql;
mod sync;

@ -0,0 +1,134 @@
/*
* Created on Fri Jan 20 2023
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use core::{
fmt,
mem::{self, size_of},
ops::Deref,
};
use crossbeam_epoch::{
Atomic as CBAtomic, CompareExchangeError, Guard, Pointable, Pointer, Shared,
};
use std::sync::atomic::Ordering;
pub(super) const ORD_RLX: Ordering = Ordering::Relaxed;
pub(super) const ORD_ACQ: Ordering = Ordering::Acquire;
pub(super) const ORD_REL: Ordering = Ordering::Release;
pub(super) const ORD_ACR: Ordering = Ordering::AcqRel;
type CxResult<'g, T, P> = Result<Shared<'g, T>, CompareExchangeError<'g, T, P>>;
pub(super) const fn ensure_flag_align<T>(fsize: usize) {
debug_assert!(mem::align_of::<T>().trailing_zeros() as usize >= fsize);
}
pub struct Atomic<T> {
a: CBAtomic<T>,
}
// the derive is stupid, it will enforce a debug constraint on T
impl<T> fmt::Debug for Atomic<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.a)
}
}
impl<T: Pointable> Atomic<T> {
// the compile time address size check ensures "first class" sanity
const _ENSURE_FLAG_STATIC_CHECK: () = ensure_flag_align::<T>(size_of::<Self>());
pub fn new_alloc(t: T) -> Self {
let _ = Self::_ENSURE_FLAG_STATIC_CHECK;
Self {
a: CBAtomic::new(t),
}
}
#[inline(always)]
pub(super) const fn null() -> Self {
Self {
a: CBAtomic::null(),
}
}
#[inline(always)]
pub(super) fn cx<'g, P>(
&self,
o: Shared<'g, T>,
n: P,
s: Ordering,
f: Ordering,
g: &'g Guard,
) -> CxResult<'g, T, P>
where
P: Pointer<T>,
{
self.a.compare_exchange(o, n, s, f, g)
}
#[inline(always)]
pub(super) fn cx_weak<'g, P>(
&self,
o: Shared<'g, T>,
n: P,
s: Ordering,
f: Ordering,
g: &'g Guard,
) -> CxResult<'g, T, P>
where
P: Pointer<T>,
{
self.a.compare_exchange_weak(o, n, s, f, g)
}
#[inline(always)]
pub(super) fn cx_rel<'g, P>(&self, o: Shared<'g, T>, n: P, g: &'g Guard) -> CxResult<'g, T, P>
where
P: Pointer<T>,
{
self.cx(o, n, ORD_REL, ORD_RLX, g)
}
#[inline(always)]
pub(super) fn ld<'g>(&self, o: Ordering, g: &'g Guard) -> Shared<'g, T> {
self.a.load(o, g)
}
#[inline(always)]
pub(super) fn ld_acq<'g>(&self, g: &'g Guard) -> Shared<'g, T> {
self.ld(ORD_ACQ, g)
}
}
impl<T, A> From<A> for Atomic<T>
where
A: Into<CBAtomic<T>>,
{
fn from(t: A) -> Self {
let _ = Self::_ENSURE_FLAG_STATIC_CHECK;
Self { a: Into::into(t) }
}
}
impl<T> Deref for Atomic<T> {
type Target = CBAtomic<T>;
fn deref(&self) -> &Self::Target {
&self.a
}
}

@ -0,0 +1,27 @@
/*
* Created on Thu Jan 19 2023
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
pub(super) mod atm;
Loading…
Cancel
Save