Skip to content

Commit e28ebc6

Browse files
committed
Thread number
1 parent 5349239 commit e28ebc6

18 files changed

+348
-64
lines changed

Cargo.lock

+266-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

czkawka_cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage = "https://github.com/qarmin/czkawka"
1010
repository = "https://github.com/qarmin/czkawka"
1111

1212
[dependencies]
13-
clap = { version = "3.2.22", features = ["derive"] }
13+
clap = { version = "3.2.23", features = ["derive"] }
1414

1515
# For enum types
1616
image_hasher = "1.1.0"

czkawka_cli/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use clap::Parser;
66

77
use commands::Commands;
88
use czkawka_core::big_file::SearchMode;
9+
use czkawka_core::common::set_default_number_of_threads;
910
#[allow(unused_imports)] // It is used in release for print_results().
1011
use czkawka_core::common_traits::*;
1112
use czkawka_core::similar_images::test_image_conversion_speed;
@@ -25,10 +26,10 @@ use czkawka_core::{
2526

2627
mod commands;
2728

28-
//noinspection ALL
2929
fn main() {
3030
let command = Commands::from_args();
3131

32+
set_default_number_of_threads();
3233
#[cfg(debug_assertions)]
3334
println!("{:?}", command);
3435

czkawka_core/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ hamming = "0.1.3"
2626

2727
# Needed by same music
2828
bitflags = "1.3.2"
29-
lofty = "0.8.1"
29+
lofty = "0.9.0"
3030

3131
# Futures - needed by async progress sender
3232
futures = "0.3.25"
@@ -56,22 +56,24 @@ serde_json = "1.0.87"
5656
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
5757
i18n-embed-fl = "0.6.4"
5858
rust-embed = "6.4.2"
59-
once_cell = "1.15.0"
59+
once_cell = "1.16.0"
6060

6161
# Raw image files
6262
rawloader = "0.37.1"
6363
imagepipe = "0.5.0"
6464

6565
# Checking for invalid extensions
6666
mime_guess = "2.0.4"
67-
infer = "0.9.0"
67+
infer = "0.11.0"
6868

6969
num_cpus = "1.13.1"
7070

7171
# Heif/Heic
7272
libheif-rs = { version = "0.15.1", optional = true }
7373
anyhow = { version = "1.0.66", optional = true }
7474

75+
state="0.5.3"
76+
7577
[features]
7678
default = []
7779
heif = ["dep:libheif-rs", "dep:anyhow"]

czkawka_core/src/common.rs

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ use imagepipe::{ImageSource, Pipeline};
1313
#[cfg(feature = "heif")]
1414
use libheif_rs::{Channel, ColorSpace, HeifContext, RgbChroma};
1515

16+
static NUMBER_OF_THREADS: state::Storage<usize> = state::Storage::new();
17+
18+
pub fn get_number_of_threads() -> usize {
19+
let data = NUMBER_OF_THREADS.get();
20+
if *data >= 1 {
21+
*data
22+
} else {
23+
num_cpus::get()
24+
}
25+
}
26+
pub fn set_default_number_of_threads() {
27+
set_number_of_threads(num_cpus::get());
28+
}
29+
pub fn get_default_number_of_threads() -> usize {
30+
num_cpus::get()
31+
}
32+
pub fn set_number_of_threads(thread_number: usize) {
33+
NUMBER_OF_THREADS.set(thread_number);
34+
35+
rayon::ThreadPoolBuilder::new().num_threads(get_number_of_threads()).build_global().unwrap();
36+
}
37+
1638
/// Class for common functions used across other class/functions
1739
pub const RAW_IMAGE_EXTENSIONS: &[&str] = &[
1840
".mrw", ".arw", ".srf", ".sr2", ".mef", ".orf", ".srw", ".erf", ".kdc", ".kdc", ".dcs", ".rw2", ".raf", ".dcr", ".dng", ".pef", ".crw", ".iiq", ".3fr", ".nrw", ".nef", ".mos",

czkawka_core/src/same_music.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl SameMusic {
376376
};
377377

378378
let result = panic::catch_unwind(move || {
379-
match read_from(&mut file, true) {
379+
match read_from(&mut file) {
380380
Ok(t) => Some(t),
381381
Err(_inspected) => {
382382
// println!("Failed to open {}", path);

czkawka_core/src/similar_images.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use serde::{Deserialize, Serialize};
2222
#[cfg(feature = "heif")]
2323
use crate::common::get_dynamic_image_from_heic;
2424
use crate::common::{
25-
create_crash_message, get_dynamic_image_from_raw_image, open_cache_folder, Common, HEIC_EXTENSIONS, IMAGE_RS_SIMILAR_IMAGES_EXTENSIONS, LOOP_DURATION, RAW_IMAGE_EXTENSIONS,
25+
create_crash_message, get_dynamic_image_from_raw_image, get_number_of_threads, open_cache_folder, Common, HEIC_EXTENSIONS, IMAGE_RS_SIMILAR_IMAGES_EXTENSIONS, LOOP_DURATION,
26+
RAW_IMAGE_EXTENSIONS,
2627
};
2728
use crate::common_directory::Directories;
2829
use crate::common_extensions::Extensions;
@@ -736,7 +737,7 @@ impl SimilarImages {
736737
let mut files_from_referenced_folders = HashMap::new();
737738
let mut normal_files = HashMap::new();
738739

739-
let number_of_processors = num_cpus::get();
740+
let number_of_processors = get_number_of_threads();
740741
let chunk_size;
741742
let mut chunks: Vec<&[&Vec<u8>]>;
742743

czkawka_gui/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/qarmin/czkawka"
1111

1212
[dependencies]
1313
gdk4 = "0.5.0"
14-
glib = "0.16.1"
14+
glib = "0.16.2"
1515

1616
humansize = "2.1.0"
1717
chrono = "0.4.22"
@@ -47,13 +47,13 @@ fs_extra = "1.2.0"
4747
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
4848
i18n-embed-fl = "0.6.4"
4949
rust-embed = "6.4.2"
50-
once_cell = "1.15.0"
50+
once_cell = "1.16.0"
5151

5252
[target.'cfg(windows)'.dependencies]
5353
winapi = { version = "0.3.9", features = ["combaseapi", "objbase", "shobjidl_core", "windef", "winerror", "wtypesbase", "winuser"] }
5454

5555
[dependencies.gtk4]
56-
version = "0.5.0"
56+
version = "0.5.1"
5757
default-features = false
5858
features = ["v4_6"]
5959

czkawka_gui/src/gui_structs/gui_settings.rs

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct GuiSettings {
2323
pub label_settings_general_language: gtk4::Label,
2424
pub combo_box_settings_language: gtk4::ComboBoxText,
2525
pub check_button_settings_one_filesystem: gtk4::CheckButton,
26+
pub label_settings_number_of_threads: gtk4::Label,
27+
pub scale_settings_number_of_threads: gtk4::Scale,
2628

2729
// Duplicates
2830
pub check_button_settings_hide_hard_links: gtk4::CheckButton,
@@ -78,6 +80,8 @@ impl GuiSettings {
7880
let check_button_settings_use_trash: gtk4::CheckButton = builder.object("check_button_settings_use_trash").unwrap();
7981
let label_settings_general_language: gtk4::Label = builder.object("label_settings_general_language").unwrap();
8082
let combo_box_settings_language: gtk4::ComboBoxText = builder.object("combo_box_settings_language").unwrap();
83+
let label_settings_number_of_threads: gtk4::Label = builder.object("label_settings_number_of_threads").unwrap();
84+
let scale_settings_number_of_threads: gtk4::Scale = builder.object("scale_settings_number_of_threads").unwrap();
8185

8286
// Duplicates
8387
let check_button_settings_hide_hard_links: gtk4::CheckButton = builder.object("check_button_settings_hide_hard_links").unwrap();
@@ -122,6 +126,8 @@ impl GuiSettings {
122126
label_settings_general_language,
123127
combo_box_settings_language,
124128
check_button_settings_one_filesystem,
129+
label_settings_number_of_threads,
130+
scale_settings_number_of_threads,
125131
check_button_settings_hide_hard_links,
126132
entry_settings_cache_file_minimal_size,
127133
entry_settings_prehash_cache_file_minimal_size,

czkawka_gui/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use connect_things::connect_selection_of_directories::*;
3232
use connect_things::connect_settings::*;
3333
use connect_things::connect_show_hide_ui::*;
3434
use connect_things::connect_similar_image_size_change::*;
35+
use czkawka_core::common::set_number_of_threads;
3536
use czkawka_core::*;
3637
use gui_structs::gui_data::*;
3738

@@ -135,6 +136,7 @@ fn build_ui(application: &Application, arguments: Vec<OsString>) {
135136
&gui_data.scrolled_window_errors,
136137
arguments.clone(),
137138
);
139+
// set_number_of_threads(gui_data.settings.sc);
138140

139141
// Needs to run when entire GUI is initialized
140142
connect_change_language(&gui_data);

czkawka_gui/ui/about_dialog.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name about_dialog.ui -->
55
<requires lib="gtk" version="4.0"/>

czkawka_gui/ui/compare_images.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name compare_images.ui -->
55
<requires lib="gtk" version="4.0"/>

czkawka_gui/ui/czkawka.cmb

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
22
<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
3-
<cambalache-project version="0.11.0" target_tk="gtk-4.0">
3+
<cambalache-project version="0.10.3" target_tk="gtk-4.0">
44
<ui>
55
(3,None,"about_dialog.ui","about_dialog.ui",None,None,None,None,None,None),
66
(4,None,"compare_images.ui","compare_images.ui",None,None,None,None,None,None),
@@ -314,7 +314,10 @@
314314
(9,52,"GtkButton","button_settings_load_configuration",51,None,None,None,None),
315315
(9,53,"GtkButton","button_settings_reset_configuration",51,None,None,None,1),
316316
(9,54,"GtkButton","button_settings_save_configuration",51,None,None,None,2),
317-
(9,55,"GtkCheckButton","check_button_settings_one_filesystem",9,None,None,None,10)
317+
(9,55,"GtkCheckButton","check_button_settings_one_filesystem",9,None,None,None,10),
318+
(9,56,"GtkBox",None,9,None,None,None,11),
319+
(9,57,"GtkLabel","label_settings_number_of_threads",56,None,None,None,None),
320+
(9,58,"GtkScale","scale_settings_number_of_threads",56,None,None,None,1)
318321
</object>
319322
<object_property>
320323
(3,1,"GtkAboutDialog","comments","2020 - 2022 Rafał Mikrut(qarmin)\n\nThis program is free to use and will always be.\n",1,None,None,None,None),
@@ -951,7 +954,15 @@
951954
(9,54,"GtkWidget","receives-default","1",None,None,None,None,None),
952955
(9,55,"GtkCheckButton","active","1",None,None,None,None,None),
953956
(9,55,"GtkCheckButton","label","Exclude other filesystems(Linux)",None,None,None,None,None),
954-
(9,55,"GtkWidget","focusable","1",None,None,None,None,None)
957+
(9,55,"GtkWidget","focusable","1",None,None,None,None,None),
958+
(9,57,"GtkLabel","label","Number of used threads",None,None,None,None,None),
959+
(9,58,"GtkRange","fill-level","100",None,None,None,None,None),
960+
(9,58,"GtkRange","round-digits","1",None,None,None,None,None),
961+
(9,58,"GtkScale","digits","0",None,None,None,None,None),
962+
(9,58,"GtkScale","draw-value","1",None,None,None,None,None),
963+
(9,58,"GtkScale","value-pos","right",None,None,None,None,None),
964+
(9,58,"GtkWidget","focusable","1",None,None,None,None,None),
965+
(9,58,"GtkWidget","hexpand","1",None,None,None,None,None)
955966
</object_property>
956967
<object_layout_property>
957968
(8,17,18,"GtkGridLayoutChild","column","0",None,None,None,None),

czkawka_gui/ui/main_window.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name main_window.ui -->
55
<requires lib="gtk" version="4.0"/>

czkawka_gui/ui/popover_right_click.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name popover_right_click.ui -->
55
<requires lib="gtk" version="4.0"/>

czkawka_gui/ui/popover_select.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name popover_select.ui -->
55
<requires lib="gtk" version="4.0"/>

czkawka_gui/ui/progress.ui

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name progress.ui -->
55
<requires lib="gtk" version="4.0"/>
@@ -75,7 +75,6 @@
7575
<property name="valign">center</property>
7676
<child>
7777
<object class="GtkBox">
78-
<property name="spacing">5</property>
7978
<child>
8079
<object class="GtkImage">
8180
<property name="icon-name">image-missing</property>

czkawka_gui/ui/settings.ui

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<!-- Created with Cambalache 0.11.2 -->
2+
<!-- Created with Cambalache 0.10.3 -->
33
<interface>
44
<!-- interface-name settings.ui -->
55
<requires lib="gtk" version="4.0"/>
@@ -114,6 +114,21 @@
114114
<property name="label">Exclude other filesystems(Linux)</property>
115115
</object>
116116
</child>
117+
<child>
118+
<object class="GtkBox">
119+
<child>
120+
<object class="GtkLabel" id="label_settings_number_of_threads">
121+
<property name="label">Number of used threads</property>
122+
</object>
123+
</child>
124+
<child>
125+
<object class="GtkScale" id="scale_settings_number_of_threads">
126+
<property name="hexpand">True</property>
127+
<property name="vexpand">True</property>
128+
</object>
129+
</child>
130+
</object>
131+
</child>
117132
</object>
118133
</child>
119134
<child>
@@ -153,7 +168,7 @@
153168
<object class="GtkCheckButton" id="check_button_settings_hide_hard_links">
154169
<property name="active">1</property>
155170
<property name="focusable">1</property>
156-
<property name="label" translatable="yes">Hide hard links(only Linux and macOS)</property>
171+
<property name="label" translatable="yes">Hide hard links(only Linux and MacOS)</property>
157172
</object>
158173
</child>
159174
<child>

0 commit comments

Comments
 (0)