rt: reduce an unnecessary lock operation
@@ -220,7 +220,6 @@ impl fmt::Debug for BlockingPool {
impl Spawner {
pub(crate) fn spawn(&self, task: Task, rt: &Handle) -> Result<(), ()> {
- let shutdown_tx = {
let mut shared = self.inner.shared.lock();
if shared.shutdown {
@@ -240,11 +239,19 @@ impl Spawner {
if shared.num_th == self.inner.thread_cap {
// At max number of threads
- None
} else {
shared.num_th += 1;
assert!(shared.shutdown_tx.is_some());
- shared.shutdown_tx.clone()
+ let shutdown_tx = shared.shutdown_tx.clone();
+
+ if let Some(shutdown_tx) = shutdown_tx {
+ let id = shared.worker_thread_index;
+ shared.worker_thread_index += 1;
+
+ let handle = self.spawn_thread(shutdown_tx, rt, id);
+
+ shared.worker_threads.insert(id, handle);
+ }
}
} else {
// Notify an idle worker thread. The notification counter
@@ -255,19 +262,6 @@ impl Spawner {
shared.num_idle -= 1;
shared.num_notify += 1;
self.inner.condvar.notify_one();
- None
- }
- };
-
- if let Some(shutdown_tx) = shutdown_tx {
- let mut shared = self.inner.shared.lock();
-
- let id = shared.worker_thread_index;
- shared.worker_thread_index += 1;
-
- let handle = self.spawn_thread(shutdown_tx, rt, id);
-
- shared.worker_threads.insert(id, handle);
}
Ok(())
