Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
examples/ | H | 03-May-2022 | - | 22 | 19 | |
script/ | H | 03-May-2022 | - | 4 | 3 | |
src/ | H | 03-May-2022 | - | 1,477 | 892 | |
.cargo-checksum.json | H A D | 03-May-2022 | 89 | 1 | 1 | |
.cargo_vcs_info.json | H A D | 01-Jan-1970 | 74 | 6 | 5 | |
.gitignore | H A D | 14-Aug-2018 | 28 | 4 | 3 | |
.travis.yml | H A D | 08-Jan-2019 | 663 | 34 | 26 | |
Cargo.toml | H A D | 01-Jan-1970 | 1,004 | 22 | 20 | |
Cargo.toml.orig-cargo | H A D | 27-Aug-2019 | 496 | 16 | 14 | |
LICENSE | H A D | 14-Aug-2018 | 1.1 KiB | 21 | 17 | |
README.md | H A D | 08-Jan-2019 | 1.4 KiB | 65 | 48 |
README.md
1spin-rs 2=========== 3 4[![Build Status](https://travis-ci.org/mvdnes/spin-rs.svg)](https://travis-ci.org/mvdnes/spin-rs) 5[![Crates.io version](https://img.shields.io/crates/v/spin.svg)](https://crates.io/crates/spin) 6[![docs.rs](https://docs.rs/spin/badge.svg)](https://docs.rs/spin/) 7 8This Rust library implements a simple 9[spinlock](https://en.wikipedia.org/wiki/Spinlock), and is safe for `#[no_std]` environments. 10 11Usage 12----- 13 14Include the following code in your Cargo.toml 15 16```toml 17[dependencies.spin] 18version = "0.5" 19``` 20 21Example 22------- 23 24When calling `lock` on a `Mutex` you will get a reference to the data. When this 25reference is dropped, the lock will be unlocked. 26 27```rust 28extern crate spin; 29 30fn main() 31{ 32 let mutex = spin::Mutex::new(0); 33 let rw_lock = spin::RwLock::new(0); 34 35 // Modify the data 36 { 37 let mut data = mutex.lock(); 38 *data = 2; 39 let mut data = rw_lock.write(); 40 *data = 3; 41 } 42 43 // Read the data 44 let answer = 45 { 46 let data1 = mutex.lock(); 47 let data2 = rw_lock.read(); 48 let data3 = rw_lock.read(); // sharing 49 (*data1, *data2, *data3) 50 }; 51 52 println!("Answers are {:?}", answer); 53} 54``` 55 56To share the lock, an `Arc<Mutex<T>>` may be used. 57 58Remarks 59------- 60 61The behaviour of these lock is similar to their namesakes in `std::sync`. they 62differ on the following: 63 64 - The lock will not be poisoned in case of failure; 65