Fixed MacOS build.
This commit is contained in:
+6
-2
@@ -16,7 +16,7 @@ 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"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
use thread_priority::{set_current_thread_priority, ThreadPriority};
|
use thread_priority::*;
|
||||||
|
|
||||||
use crate::blockchain::hash_utils::*;
|
use crate::blockchain::hash_utils::*;
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
@@ -27,6 +27,7 @@ use blakeout::Blakeout;
|
|||||||
use self::crypto::digest::Digest;
|
use self::crypto::digest::Digest;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use thread_priority::set_current_thread_ideal_processor;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Keystore {
|
pub struct Keystore {
|
||||||
@@ -119,13 +120,16 @@ pub fn create_key(context: Arc<Mutex<Context>>) {
|
|||||||
let mining = Arc::new(AtomicBool::new(true));
|
let mining = Arc::new(AtomicBool::new(true));
|
||||||
let miners_count = Arc::new(AtomicUsize::new(0));
|
let miners_count = Arc::new(AtomicUsize::new(0));
|
||||||
{ context.lock().unwrap().bus.post(Event::KeyGeneratorStarted); }
|
{ context.lock().unwrap().bus.post(Event::KeyGeneratorStarted); }
|
||||||
for _ in 0..num_cpus::get() {
|
for cpu in 0..num_cpus::get() {
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
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"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
{
|
||||||
let _ = set_current_thread_priority(ThreadPriority::Min);
|
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 => {
|
||||||
|
|||||||
+3
-1
@@ -168,8 +168,10 @@ impl Miner {
|
|||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
{
|
||||||
let _ = set_current_thread_priority(ThreadPriority::Min);
|
let _ = set_current_thread_priority(ThreadPriority::Min);
|
||||||
let _ = set_current_thread_ideal_processor(IdealProcessor::from(cpu as u32));
|
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) {
|
||||||
@@ -214,7 +216,7 @@ fn find_hash(context: Arc<Mutex<Context>>, digest: &mut dyn Digest, mut block: B
|
|||||||
block.prev_block_hash = last_block.hash;
|
block.prev_block_hash = last_block.hash;
|
||||||
if block.transaction.is_some() && last_block.transaction.is_some() {
|
if block.transaction.is_some() && last_block.transaction.is_some() {
|
||||||
// We can't mine our domain block over a block with domain
|
// We can't mine our domain block over a block with domain
|
||||||
// TODO make a method in Chain to get next available to mine bock index
|
// TODO make a method in Chain to get next available to mine block index
|
||||||
thread::sleep(Duration::from_millis(1000));
|
thread::sleep(Duration::from_millis(1000));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user