aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-01-17 20:04:19 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-01-17 20:04:19 +0100
commit088f292c1101adb15716705fd0e753de9668f9cf (patch)
tree9d7e9cc137d1e3c682ab1a8c9c85434b005cba83
parentd8c7164cbdc2ccb1ab3cbfbd3aabad1921a2501a (diff)
downloadhittekaart-088f292c1101adb15716705fd0e753de9668f9cf.tar.gz
hittekaart-088f292c1101adb15716705fd0e753de9668f9cf.tar.bz2
hittekaart-088f292c1101adb15716705fd0e753de9668f9cf.zip
replace std::mpsc with crossbeam_channel
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/renderer.rs7
3 files changed, 5 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b995bd3..03fb13b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -605,6 +605,7 @@ dependencies = [
"color-eyre",
"colorgrad",
"criterion",
+ "crossbeam-channel",
"flate2",
"fnv",
"image",
diff --git a/Cargo.toml b/Cargo.toml
index f50423e..3c9b45d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,7 @@ brotli = "3.3.4"
clap = { version = "4.1.0", features = ["derive"] }
color-eyre = "0.6.2"
colorgrad = "0.6.2"
+crossbeam-channel = "0.5.6"
flate2 = "1.0.25"
fnv = "1.0.7"
image = "0.24.5"
diff --git a/src/renderer.rs b/src/renderer.rs
index de65da6..bb33ddc 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -1,4 +1,4 @@
-use std::{fs, mem, path::Path, sync::mpsc, thread};
+use std::{fs, path::Path, thread};
use color_eyre::{
eyre::{bail, Result},
@@ -147,7 +147,7 @@ pub fn lazy_colorization<P: AsRef<Path>, F: Fn(usize) + Send + Sync>(
}
type Job = (u64, u64, Vec<u8>);
- let (tx, rx) = mpsc::sync_channel::<Job>(30);
+ let (tx, rx) = crossbeam_channel::bounded::<Job>(30);
thread::scope(|s| {
let saver = s.spawn(move || loop {
@@ -165,7 +165,7 @@ pub fn lazy_colorization<P: AsRef<Path>, F: Fn(usize) + Send + Sync>(
layer
.into_parallel_tiles()
- .try_for_each(|(tile_x, tile_y, tile)| {
+ .try_for_each_with(tx, |tx, (tile_x, tile_y, tile)| {
let colorized = colorize_tile(&tile, max.into());
let data = layer::compress_png_as_bytes(&colorized)?;
tx.send((tile_x, tile_y, data))?;
@@ -173,7 +173,6 @@ pub fn lazy_colorization<P: AsRef<Path>, F: Fn(usize) + Send + Sync>(
Ok::<(), Report>(())
})?;
- mem::drop(tx);
saver.join().unwrap()?;
Ok::<_, Report>(())
})?;