1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright 2016 Joshua Gentry
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*/
//! This crate allows the sharing of various data objects via atomic memory operations to avoid
//! the overhead of Mutex whenever possible. The SharedF32, SharedI8, SharedI16, SharedI32,
//! SharedIsize, SharedU8, SharedU16, SharedU32, and SharedUsize objects basically just pass
//! the data to the atomic elements.
//!
//! The SharedF64, SharedI64 and SharedU64 objects are useful when supporting both 32 and 64 bit
//! environments. Under 64 bit environments they will use the faster atomic data objects to share
//! the values, when compiled under 32 bit they will use the slower mutexes since the atomics only
//! handle 32 bit values.
//!
//! The SharedObject will share a read only object. Internally it uses a very small spin lock to
//! to insure accurate reference counting but should provide faster access than using a Mutex.
//!
//! # Examples
//!
//! ```
//! use std::sync::mpsc;
//! use std::thread;
//! use shareable::SharedObject;
//!
//! let value1 = SharedObject::new(String::from("abc"));
//! let value2 = value1.clone();
//!
//! let (tx, rx) = mpsc::channel();
//!
//! let thread = thread::spawn(move || {
//! rx.recv();
//! assert_eq!(value2.get().as_str(), "xyz");
//! });
//!
//! value1.set(String::from("xyz"));
//!
//! tx.send(());
//! thread.join().unwrap();
//! ```
pub use SharedBool;
pub use SharedF32;
pub use SharedF64;
pub use SharedI8;
pub use SharedI16;
pub use SharedI32;
pub use SharedI64;
pub use SharedIsize;
pub use SharedObject;
pub use SharedU8;
pub use SharedU16;
pub use SharedU32;
pub use SharedU64;
pub use SharedUsize;