-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add crate infallible and parallel-executor
- Loading branch information
Showing
14 changed files
with
1,303 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod mutex; | ||
|
||
pub use mutex::{Mutex, MutexGuard}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; |
Oops, something went wrong.