Skip to content

Commit

Permalink
🍋 Cargo doc friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonHX committed Apr 14, 2021
1 parent 98de258 commit 48a4eef
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 183 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

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

18 changes: 1 addition & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
[package]
name = "optimistic_lock_coupling"
version = "0.2.0"
version = "0.2.5"
authors = ["lemonhx <lemonhx@lemonhx.tech>"]
edition = "2018"
description = "A General Lock following paper 'Optimistic Lock Coupling: A Scalable and Efficient General-Purpose Synchronization Method' "
license = "Unlicense"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "optimistic_lock_coupling"
path = "src/lib.rs"

[[bin]]
name = "read_example"
path = "example/read.rs"
[[bin]]
name = "write_example"
path = "example/write.rs"
[[bin]]
name = "multi_thread_example"
path = "example/multi_thread.rs"


[[bench]]
name = "benchmark"
harness = false
Expand Down
2 changes: 0 additions & 2 deletions example/multi_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ fn main() {
use std::thread::spawn;
let thread1 = spawn(write_fn);
let thread2 = spawn(read_fn);
let thread3 = spawn(read_fn);

let _ = thread1.join();
let _ = thread2.join();
let _ = thread3.join();
unsafe { assert_eq!(*(lock.as_ref().unwrap().write().unwrap()), i) }
}
15 changes: 12 additions & 3 deletions example/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ fn read_txn(lock: &OptimisticLockCoupling<i32>) -> Result<(), OptimisticLockCoup
fn main() {
let lock = OptimisticLockCoupling::new(1);
// retry steps
'retry: loop{
'retry: loop {
// function call
let res = read_txn(&lock);
// before retry logics
if res.is_err() {
continue 'retry;
}else{
} else {
break 'retry;
}
}
}
// or
lock.read_txn(
#[inline(always)]
|guard| {
println!("{}", guard);
Ok(())
},
)
.unwrap();
}
Loading

0 comments on commit 48a4eef

Please sign in to comment.