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