Skip to content

Commit

Permalink
add crate infallible and parallel-executor
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed May 22, 2023
1 parent 8412dc9 commit 0ea3883
Show file tree
Hide file tree
Showing 14 changed files with 1,303 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"commons/accumulator",
"commons/forkable-jellyfish-merkle",
"commons/time-service",
"commons/infallible",
"types",
"types/uint",
"genesis",
Expand Down Expand Up @@ -74,6 +75,7 @@ members = [
"vm/compiler",
"vm/move-prover",
"vm/mvhashmap",
"vm/parallel-executor",
"vm/transaction-builder",
"vm/transaction-builder-generator",
"vm/move-coverage",
Expand Down Expand Up @@ -123,6 +125,7 @@ default-members = [
"commons/api-limiter",
"commons/accumulator",
"commons/forkable-jellyfish-merkle",
"commons/infallible",
"types",
"types/uint",
"genesis",
Expand Down Expand Up @@ -178,6 +181,7 @@ default-members = [
"vm/compiler",
"vm/move-prover",
"vm/mvhashmap",
"vm/parallel-executor",
"vm/transaction-builder",
"vm/transaction-builder-generator",
"vm/move-coverage",
Expand Down Expand Up @@ -482,6 +486,9 @@ stdlib = { path = "vm/stdlib" }
stest = { path = "commons/stest" }
stest-macro = { path = "commons/stest/stest-macro" }
stream-task = { path = "commons/stream-task" }
starcoin-mvhashmap = { path = "vm/mvhashmap" }
starcoin-parallel-executor = { path = "vm/parallel-executor" }
starcoin-infallible = { path = "commons/infallible" }
syn = { version = "1.0.107", features = [
"full",
"extra-traits",
Expand Down
8 changes: 8 additions & 0 deletions commons/infallible/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "starcoin-infallible"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions commons/infallible/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod mutex;

pub use mutex::{Mutex, MutexGuard};
54 changes: 54 additions & 0 deletions commons/infallible/src/mutex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

use std::sync::Mutex as StdMutex;

pub use std::sync::MutexGuard;

/// A simple wrapper around the lock() function of a std::sync::Mutex
/// The only difference is that you don't need to call unwrap() on it.
#[derive(Debug)]
pub struct Mutex<T>(StdMutex<T>);

impl<T> Mutex<T> {
/// creates mutex
pub fn new(t: T) -> Self {
Self(StdMutex::new(t))
}

/// lock the mutex
pub fn lock(&self) -> MutexGuard<'_, T> {
self.0
.lock()
.expect("Cannot currently handle a poisoned lock")
}
}

#[cfg(test)]
mod tests {

use super::*;
use std::{sync::Arc, thread};

#[test]
fn test_mutex() {
let a = 7u8;
let mutex = Arc::new(Mutex::new(a));
let mutex2 = mutex.clone();
let mutex3 = mutex.clone();

let thread1 = thread::spawn(move || {
let mut b = mutex2.lock();
*b = 8;
});
let thread2 = thread::spawn(move || {
let mut b = mutex3.lock();
*b = 9;
});

let _ = thread1.join();
let _ = thread2.join();

let _locked = mutex.lock();
}
}
2 changes: 1 addition & 1 deletion vm/mvhashmap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
authors = { workspace = true }
description = "starcoin Move VM starcoin-mvhashmap"
description = "Starcoin Move VM starcoin-mvhashmap"
edition = { workspace = true }
license = { workspace = true }
name = "starcoin-mvhashmap"
Expand Down
23 changes: 23 additions & 0 deletions vm/parallel-executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = { workspace = true }
description = "Starcoin parallel transaction executor library"
edition = { workspace = true }
license = { workspace = true }
name = "starcoin-parallel-executor"
publish = { workspace = true }
version = "1.13.4"
homepage = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }


[dependencies]
once_cell = { workspace = true }
rayon = { workspace = true }
num_cpus = { workspace = true }
crossbeam = { workspace = true }
dashmap = { workspace = true }
arc-swap = { workspace = true }
anyhow = { workspace = true }
starcoin-infallible = { workspace = true }
starcoin-mvhashmap = { workspace = true }
19 changes: 19 additions & 0 deletions vm/parallel-executor/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

#[derive(Debug)]
pub enum Error<E> {
/// Invariant violation that happens internally inside of scheduler, usually an indication of
/// implementation error.
InvariantViolation,
/// The inference can't get the read/write set of a transaction, abort the entire execution pipeline.
InferencerError,
/// A transaction write to a key that wasn't estimated by the inferencer, abort the execution
/// because we don't have a good way of handling read-after-write dependency. Will relax this limitation later.
UnestimatedWrite,
/// Execution of a thread yields a non-recoverable error, such error will be propagated back to
/// the caller.
UserError(E),
}

pub type Result<T, E> = ::std::result::Result<T, Error<E>>;
Loading

0 comments on commit 0ea3883

Please sign in to comment.