Skip to content

Commit

Permalink
Update dependencies, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbool committed Jan 31, 2019
1 parent c4a3081 commit 55dccdb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
[package]

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

[dependencies]
variance = "0.1"
crossbeam = "0.2"
scopeguard = "0.1"
variance = "0.1.3"
crossbeam-channel = "0.3.8"
scopeguard = "1.0.0"

[dev-dependencies]
rand = "0.3"
itertools = "0.4"

rand = "0.6.5"
itertools = "0.8.0"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ with the rest of your dependencies:

```toml
[dependencies]
scoped-pool = "1"
scoped-pool = "1.1"
```

`scoped-pool` currently requires Rust 1.11.

## Author

[Jonathan Reem](https://medium.com/@jreem) is the primary author and maintainer of scoped-pool.
Expand Down
32 changes: 19 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//!
extern crate variance;
extern crate crossbeam;
extern crate crossbeam_channel;

#[macro_use]
extern crate scopeguard;

use variance::InvariantLifetime as Id;
use crossbeam::sync::MsQueue;
use crossbeam_channel::{Sender, Receiver};

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

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

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

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

// Terminate the thread.
break
break;
},

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

struct PoolInner {
queue: MsQueue<PoolMessage>,
tx: Sender<PoolMessage>,
rx: Receiver<PoolMessage>,
thread_config: ThreadConfig,
thread_counter: AtomicUsize
thread_counter: AtomicUsize,
}

impl PoolInner {
fn with_thread_config(thread_config: ThreadConfig) -> Self {
PoolInner { thread_config: thread_config, ..Self::default() }
PoolInner {
thread_config,
..Default::default()
}
}
}

impl Default for PoolInner {
fn default() -> Self {
let (tx, rx) = crossbeam_channel::unbounded();
PoolInner {
queue: MsQueue::new(),
tx,
rx,
thread_config: ThreadConfig::default(),
thread_counter: AtomicUsize::new(1)
}
Expand Down Expand Up @@ -279,7 +285,7 @@ impl<'scope> Scope<'scope> {
#[inline]
pub fn forever(pool: Pool) -> Scope<'static> {
Scope {
pool: pool,
pool,
wait: Arc::new(WaitGroup::new()),
_scope: Id::default()
}
Expand All @@ -301,7 +307,7 @@ impl<'scope> Scope<'scope> {
};

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

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

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

0 comments on commit 55dccdb

Please sign in to comment.