Skip to content

Commit 32254e1

Browse files
committed
Update dependencies, bump version
1 parent c4a3081 commit 32254e1

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
[package]
22

33
name = "scoped-pool"
4-
version = "1.0.0"
4+
version = "1.1.0"
55
authors = ["Jonathan Reem <[email protected]>"]
66
repository = "https://github.com/reem/rust-scoped-pool.git"
77
description = "A flexible thread pool providing scoped threads."
88
readme = "README.md"
99
license = "MIT"
1010

1111
[dependencies]
12-
variance = "0.1"
13-
crossbeam = "0.2"
14-
scopeguard = "0.1"
12+
variance = "0.1.3"
13+
crossbeam-channel = "0.3.8"
14+
scopeguard = "1.0.0"
1515

1616
[dev-dependencies]
17-
rand = "0.3"
18-
itertools = "0.4"
19-
17+
rand = "0.6.5"
18+
itertools = "0.8.0"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ with the rest of your dependencies:
6565

6666
```toml
6767
[dependencies]
68-
scoped-pool = "1"
68+
scoped-pool = "1.1"
6969
```
7070

71+
`scoped-pool` currently requires Rust 1.28.
72+
7173
## Author
7274

7375
[Jonathan Reem](https://medium.com/@jreem) is the primary author and maintainer of scoped-pool.

src/lib.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
//!
88
99
extern crate variance;
10-
extern crate crossbeam;
10+
extern crate crossbeam_channel;
1111

1212
#[macro_use]
1313
extern crate scopeguard;
1414

1515
use variance::InvariantLifetime as Id;
16-
use crossbeam::sync::MsQueue;
16+
use crossbeam_channel::{Sender, Receiver};
1717

1818
use std::{thread, mem};
1919
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
@@ -128,7 +128,7 @@ impl Pool {
128128
#[inline]
129129
pub fn shutdown(&self) {
130130
// Start the shutdown process.
131-
self.inner.queue.push(PoolMessage::Quit);
131+
let _ = self.inner.tx.send(PoolMessage::Quit);
132132

133133
// Wait for it to complete.
134134
self.wait.join()
@@ -165,18 +165,18 @@ impl Pool {
165165
let mut thread_sentinel = ThreadSentinel(Some(self.clone()));
166166

167167
loop {
168-
match self.inner.queue.pop() {
168+
match self.inner.rx.recv().unwrap() {
169169
// On Quit, repropogate and quit.
170170
PoolMessage::Quit => {
171171
// Repropogate the Quit message to other threads.
172-
self.inner.queue.push(PoolMessage::Quit);
172+
let _ = self.inner.tx.send(PoolMessage::Quit);
173173

174174
// Cancel the thread sentinel so we don't panic waiting
175175
// shutdown threads, and don't restart the thread.
176176
thread_sentinel.cancel();
177177

178178
// Terminate the thread.
179-
break
179+
break;
180180
},
181181

182182
// On Task, run the task then complete the WaitGroup.
@@ -191,21 +191,27 @@ impl Pool {
191191
}
192192

193193
struct PoolInner {
194-
queue: MsQueue<PoolMessage>,
194+
tx: Sender<PoolMessage>,
195+
rx: Receiver<PoolMessage>,
195196
thread_config: ThreadConfig,
196-
thread_counter: AtomicUsize
197+
thread_counter: AtomicUsize,
197198
}
198199

199200
impl PoolInner {
200201
fn with_thread_config(thread_config: ThreadConfig) -> Self {
201-
PoolInner { thread_config: thread_config, ..Self::default() }
202+
PoolInner {
203+
thread_config,
204+
..Default::default()
205+
}
202206
}
203207
}
204208

205209
impl Default for PoolInner {
206210
fn default() -> Self {
211+
let (tx, rx) = crossbeam_channel::unbounded();
207212
PoolInner {
208-
queue: MsQueue::new(),
213+
tx,
214+
rx,
209215
thread_config: ThreadConfig::default(),
210216
thread_counter: AtomicUsize::new(1)
211217
}
@@ -279,7 +285,7 @@ impl<'scope> Scope<'scope> {
279285
#[inline]
280286
pub fn forever(pool: Pool) -> Scope<'static> {
281287
Scope {
282-
pool: pool,
288+
pool,
283289
wait: Arc::new(WaitGroup::new()),
284290
_scope: Id::default()
285291
}
@@ -301,7 +307,7 @@ impl<'scope> Scope<'scope> {
301307
};
302308

303309
// Submit the task to be executed.
304-
self.pool.inner.queue.push(PoolMessage::Task(task, self.wait.clone()));
310+
let _ = self.pool.inner.tx.send(PoolMessage::Task(task, self.wait.clone()));
305311
}
306312

307313
/// Add a job to this scope which itself will get access to the scope.
@@ -322,7 +328,7 @@ impl<'scope> Scope<'scope> {
322328
pub fn zoom<'smaller, F, R>(&self, scheduler: F) -> R
323329
where F: FnOnce(&Scope<'smaller>) -> R,
324330
'scope: 'smaller {
325-
let scope = unsafe { self.refine::<'smaller>() };
331+
let scope = unsafe { self.refine() };
326332

327333
// Join the scope either on completion of the scheduler or panic.
328334
defer!(scope.join());

0 commit comments

Comments
 (0)