Refactored setup of mining threads.

This commit is contained in:
Revertron
2021-03-16 20:54:44 +01:00
parent 8d56fcb5e7
commit 99eabff874
3 changed files with 17 additions and 16 deletions
+2 -8
View File
@@ -15,11 +15,9 @@ use crypto::ed25519::{keypair, signature, verify};
use log::{debug, error, info, trace, warn};
use rand::{Rng, RngCore, thread_rng};
use serde::{Deserialize, Serialize};
#[cfg(not(target_os = "macos"))]
use thread_priority::*;
use crate::blockchain::hash_utils::*;
use crate::Context;
use crate::{Context, setup_miner_thread};
use crate::event::Event;
use crate::blockchain::KEYSTORE_DIFFICULTY;
use crate::bytes::Bytes;
@@ -124,11 +122,7 @@ pub fn create_key(context: Arc<Mutex<Context>>) {
let mining = mining.clone();
let miners_count = miners_count.clone();
thread::spawn(move || {
#[cfg(not(target_os = "macos"))]
{
let _ = set_current_thread_priority(ThreadPriority::Min);
let _ = set_current_thread_ideal_processor(IdealProcessor::from(cpu as u32));
}
setup_miner_thread(cpu as u32);
miners_count.fetch_add(1, atomic::Ordering::SeqCst);
match generate_key(KEYSTORE_DIFFICULTY, mining.clone()) {
None => {
+2 -8
View File
@@ -8,10 +8,8 @@ use crypto::digest::Digest;
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
use num_cpus;
#[cfg(not(target_os = "macos"))]
use thread_priority::*;
use crate::{Block, Bytes, Context};
use crate::{Block, Bytes, Context, setup_miner_thread};
use crate::blockchain::{BLOCK_DIFFICULTY, CHAIN_VERSION, LOCKER_DIFFICULTY, KEYSTORE_DIFFICULTY};
use crate::blockchain::enums::BlockQuality;
use crate::blockchain::hash_utils::*;
@@ -167,11 +165,7 @@ impl Miner {
true
});
#[cfg(not(target_os = "macos"))]
{
let _ = set_current_thread_priority(ThreadPriority::Min);
let _ = set_current_thread_ideal_processor(IdealProcessor::from(cpu as u32));
}
setup_miner_thread(cpu as u32);
live_threads.fetch_add(1, Ordering::SeqCst);
let mut hasher = get_hasher_for_version(block.version);
match find_hash(Arc::clone(&context), &mut *hasher, block, Arc::clone(&mining), top_block) {
+13
View File
@@ -1,4 +1,6 @@
use std::num;
#[cfg(not(target_os = "macos"))]
use thread_priority::*;
/// Convert bytes array to HEX format
pub fn to_hex(buf: &[u8]) -> String {
@@ -16,6 +18,17 @@ pub fn from_hex(string: &str) -> Result<Vec<u8>, num::ParseIntError> {
.collect()
}
#[cfg(not(target_os = "macos"))]
pub fn setup_miner_thread(cpu: u32) {
let _ = set_current_thread_priority(ThreadPriority::Min);
let _ = set_current_thread_ideal_processor(IdealProcessor::from(cpu));
}
#[cfg(target_os = "macos")]
pub fn setup_miner_thread(cpu: u32) {
// MacOS is not supported by thread_priority crate
}
pub fn check_domain(name: &str, allow_dots: bool) -> bool {
if name.starts_with('.') || name.starts_with('-') || name.ends_with('.') || name.ends_with('-') {
return false;