Skip to content

Commit

Permalink
Tests: Fix doc-tests for README.md
Browse files Browse the repository at this point in the history
cfg(test) is no longer set during doctests
See: rust-lang/rust#45599
  • Loading branch information
Brian Gianforcaro committed Dec 2, 2019
1 parent 1cbdd9a commit 4bfc8a4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ travis-ci = { repository = "bgianfo/rust-run-down", branch = "master" }
bitflags = "1.2.1"
lazy-init = "0.3.0"
rsevents = "0.2.0"
# See: https://github.com/rust-lang/rust/issues/45599
doc-comment = "0.3.1"

[dev-dependencies]
assert-impl = "0.1.3"
pretty_assertions = "0.6"
doc-comment = "0.3.1"
61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,47 @@ and the ability to wait for all outstanding usages to drain so you can safely pe

This crate was inspired by the [run-down protection primitive available in the NT Kernel][nt-run-down-docs].


## Usage example

````rust
use run_down::{RundownGuard, RundownRef};
```rust
use run_down::{
RundownGuard,
RundownRef
};
use std::sync::Arc;
use std::thread;
use std::time::Duration;

fn example() {
let rundown = Arc::new(RundownRef::new());

for i in 1..25 {

let rundown = Arc::new(RundownRef::new());
let rundown_clone = Arc::clone(&rundown);

for _ in 0..50 {
thread::spawn(move || {

let rundown_clone = Arc::clone(&rundown);

thread::spawn(move || {

// Attempt to acquire rundown protection, while the main
// thread could be running down the object as we execute.
//
match rundown_clone.try_acquire() {
Ok(_) => {
println!("{}: Run-down protection acquired.", thread::current().id());

// Stall the thread while holding rundown protection.
thread::sleep(Duration::from_millis(10));
}
Err(m) => {
println!("{}: Failed to acquire run-down protection - {}",
thread::current().id(),
m);
},
// Attempt to acquire rundown protection, while the main
// thread could be running down the object as we execute.
//
match rundown_clone.try_acquire() {
Ok(_) => {
println!("{}: Run-down protection acquired.", i);

// Stall the thread while holding rundown protection.
thread::sleep(Duration::from_millis(10));
}
});
}

println!("{}: Waiting for rundown to complete", thread::current().id());
rundown.wait_for_rundown();
println!("{}: Rundown complete", thread::current().id());
Err(m) => {
println!("{}: Failed to acquire run-down protection - {:?}", i, m);
},
}
});
}
````

println!("0: Waiting for rundown to complete");
rundown.wait_for_rundown();
println!("0: Rundown complete");
```

## TODO

Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ mod rundown_ref;
pub use guard::RundownGuard;
pub use rundown_ref::RundownError;
pub use rundown_ref::RundownRef;

extern crate doc_comment;

// Test examples in the README file.
doc_comment::doctest!("../README.md", readme_examples);
9 changes: 0 additions & 9 deletions tests/docs.rs

This file was deleted.

0 comments on commit 4bfc8a4

Please sign in to comment.