Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Sep 17, 2024
1 parent f03e756 commit 39cb1f3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rayon = "1.10.0"
tokio = { version = "1.40.0", features = ["full"] }
once_cell = "1.19.0"
num_cpus = "1.16.0"
crossbeam-queue = "0.3.11"

[build-dependencies]
serde = { version = "1.0.210", features = ["derive"] }
Expand Down
51 changes: 31 additions & 20 deletions Source/Fn/Binary/Command/Parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod Process;
/// ```
pub async fn Fn(Option { Entry, Separator, Pattern, Command, .. }: Option) {
let (Approval, mut Receive) = tokio::sync::mpsc::unbounded_channel();
let Force = rayon::current_num_threads();

let Entry = Entry
.into_par_iter()
Expand All @@ -42,32 +43,40 @@ pub async fn Fn(Option { Entry, Separator, Pattern, Command, .. }: Option) {
})
.collect::<Vec<String>>();

let Pool = Arc::new(rayon::ThreadPoolBuilder::new().build().expect("Cannot build."));
let Queue = Arc::new(crossbeam_queue::ArrayQueue::new(Entry.len()));

Entry.into_par_iter().for_each(|Entry| {
let Command = Command.clone();
let Approval = Approval.clone();
for Entry in Entry {
Queue.push(Entry).expect("Cannot push.");
}

Pool.spawn(move || {
let Output = tokio::runtime::Runtime::new().unwrap().block_on(async move {
let mut Output = Vec::new();
(0..Force).into_par_iter().for_each(|_| {
let Runtime = tokio::runtime::Runtime::new().expect("Cannot Runtime.");

for Command in &Command {
let Command: Vec<String> = Command.split(' ').map(String::from).collect();
Runtime.block_on(async {
let Queue = Arc::clone(&Queue);
let Approval = Approval.clone();
let Command = Command.clone();

if GPG::Fn(&Command) {
let Lock = GPG_MUTEX.lock().expect("Cannot lock.");
drop(Lock);
}
loop {
if let Some(Entry) = Queue.pop() {
let mut Output = Vec::new();

Output.push(Process::Fn(&Command, &Entry).await);
}
for Command in &Command {
let Command: Vec<String> = Command.split(' ').map(String::from).collect();

if GPG::Fn(&Command) {
let _Lock = GPG_MUTEX.lock().await;
}

Output
});
Output.push(Process::Fn(&Command, &Entry).await);
}

if let Err(_) = Approval.send(Output) {
eprintln!("Cannot send.");
if let Err(_) = Approval.send(Output) {
eprintln!("Cannot send.");
}
} else {
break;
}
}
});
});
Expand All @@ -82,8 +91,10 @@ pub async fn Fn(Option { Entry, Separator, Pattern, Command, .. }: Option) {
}

use crate::Struct::Binary::Command::Entry::Struct as Option;

use once_cell::sync::Lazy;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use tokio::sync::Mutex;

static GPG_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
Binary file modified Target/release/Inn.exe
Binary file not shown.
Binary file modified Target/release/InnKeeper.exe
Binary file not shown.
Binary file modified Target/release/PRun.exe
Binary file not shown.
Binary file modified Target/release/Run.exe
Binary file not shown.

0 comments on commit 39cb1f3

Please sign in to comment.