-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Modules now run in separate threads (#4)
To be honest it was hell of a mess, not sure if it's an ideal solution but hey; it works :D
- Loading branch information
Showing
7 changed files
with
133 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::sync::{ | ||
atomic::{AtomicUsize, Ordering}, | ||
Arc, Mutex, | ||
}; | ||
|
||
use crate::logger; | ||
|
||
pub struct State { | ||
active_tasks: Arc<AtomicUsize>, | ||
verbose: bool, | ||
|
||
discovered_subdomains: Mutex<Vec<String>>, | ||
} | ||
|
||
impl State { | ||
pub fn new(verbose: bool) -> Self { | ||
State { | ||
active_tasks: Arc::new(AtomicUsize::new(0)), | ||
verbose, | ||
|
||
discovered_subdomains: Mutex::new(Vec::new()), | ||
} | ||
} | ||
|
||
pub fn is_verbose(&self) -> bool { | ||
self.verbose | ||
} | ||
|
||
pub fn increment_tasks(&self) { | ||
self.active_tasks.fetch_add(1, Ordering::SeqCst); | ||
if self.is_verbose() { | ||
logger::debug( | ||
"state", | ||
format!( | ||
"The running task counter has incremented, current running tasks: {}", | ||
self.active_tasks_count() | ||
), | ||
); | ||
} | ||
} | ||
|
||
pub fn decrement_tasks(&self) { | ||
self.active_tasks.fetch_sub(1, Ordering::SeqCst); | ||
if self.is_verbose() { | ||
logger::debug( | ||
"state", | ||
format!( | ||
"The running task counter has decremented, current running tasks: {}", | ||
self.active_tasks_count() | ||
), | ||
); | ||
} | ||
} | ||
|
||
pub fn active_tasks_count(&self) -> usize { | ||
self.active_tasks.load(Ordering::SeqCst) | ||
} | ||
|
||
pub fn discover_subdomain(&self, subdomain: String) { | ||
self.discovered_subdomains.lock().unwrap().push(subdomain) | ||
} | ||
|
||
pub fn has_discovered_subdomain(&self, subdomain: String) -> bool { | ||
self.discovered_subdomains | ||
.lock() | ||
.unwrap() | ||
.contains(&subdomain) | ||
} | ||
} |