]>
git.proxmox.com Git - rustc.git/blob - vendor/crossbeam-queue-0.1.2/tests/seg_queue.rs
1 extern crate crossbeam_queue
;
2 extern crate crossbeam_utils
;
5 use std
::sync
::atomic
::{AtomicUsize, Ordering}
;
7 use crossbeam_queue
::SegQueue
;
8 use crossbeam_utils
::thread
::scope
;
9 use rand
::{thread_rng, Rng}
;
13 let q
= SegQueue
::new();
15 assert_eq
!(q
.pop(), Ok(7));
18 assert_eq
!(q
.pop(), Ok(8));
19 assert
!(q
.pop().is_err());
24 let q
= SegQueue
::new();
26 assert_eq
!(q
.len(), 0);
27 assert_eq
!(q
.is_empty(), true);
31 assert_eq
!(q
.len(), 1);
32 assert_eq
!(q
.is_empty(), false);
36 assert_eq
!(q
.len(), 0);
37 assert_eq
!(q
.is_empty(), true);
42 let q
= SegQueue
::new();
44 assert_eq
!(q
.len(), 0);
48 assert_eq
!(q
.len(), i
+ 1);
53 assert_eq
!(q
.len(), 50 - i
- 1);
56 assert_eq
!(q
.len(), 0);
61 const COUNT
: usize = 100_000;
63 let q
= SegQueue
::new();
69 if let Ok(x
) = q
.pop() {
75 assert
!(q
.pop().is_err());
87 const COUNT
: usize = 25_000;
88 const THREADS
: usize = 4;
90 let q
= SegQueue
::<usize>::new();
91 let v
= (0..COUNT
).map(|_
| AtomicUsize
::new(0)).collect
::<Vec
<_
>>();
98 if let Ok(x
) = q
.pop() {
102 v
[n
].fetch_add(1, Ordering
::SeqCst
);
106 for _
in 0..THREADS
{
116 assert_eq
!(c
.load(Ordering
::SeqCst
), THREADS
);
122 static DROPS
: AtomicUsize
= AtomicUsize
::new(0);
124 #[derive(Debug, PartialEq)]
127 impl Drop
for DropCounter
{
129 DROPS
.fetch_add(1, Ordering
::SeqCst
);
133 let mut rng
= thread_rng();
136 let steps
= rng
.gen_range(0, 10_000);
137 let additional
= rng
.gen_range(0, 1000);
139 DROPS
.store(0, Ordering
::SeqCst
);
140 let q
= SegQueue
::new();
145 while q
.pop().is_err() {}
156 for _
in 0..additional
{
160 assert_eq
!(DROPS
.load(Ordering
::SeqCst
), steps
);
162 assert_eq
!(DROPS
.load(Ordering
::SeqCst
), steps
+ additional
);