From 980ffeec12db75362788c0b78b88bacf9489cf63 Mon Sep 17 00:00:00 2001 From: Haifa Bogdan Adnan Date: Wed, 29 Aug 2018 18:42:42 +0300 Subject: [PATCH] Small fix. --- hash/gpu/gpu_hasher.cpp | 6 ++-- hash/hasher.cpp | 65 ++++++++++++++++++++++++++++------------- hash/hasher.h | 3 +- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/hash/gpu/gpu_hasher.cpp b/hash/gpu/gpu_hasher.cpp index 0939640..c78d16c 100755 --- a/hash/gpu/gpu_hasher.cpp +++ b/hash/gpu/gpu_hasher.cpp @@ -704,11 +704,13 @@ void gpu_hasher::__run(gpu_device_info *device, int thread_id) { if (device->error != CL_SUCCESS) { LOG("Error running kernel: (" + to_string(device->error) + ")" + device->error_message); } + vector stored_hashes; for(vector::iterator it = hashes.begin(); it != hashes.end(); ++it) { input.hash = *it; - _store_hash(input); + stored_hashes.push_back(input); } - } + _store_hash(stored_hashes); + } // printf("Total time: %lld\n", microseconds() - start_log); } free(memory); diff --git a/hash/hasher.cpp b/hash/hasher.cpp index 07b71b2..6954fc1 100755 --- a/hash/hasher.cpp +++ b/hash/hasher.cpp @@ -180,27 +180,52 @@ vector hasher::get_hashes() { } void hasher::_store_hash(const hash_data &hash) { -// LOG(hash.hash); - __hashes_mutex.lock(); - __hashes.push_back(hash); - __hash_count++; - __hashrate_hashcount++; - if(hash.profile_name == "1_1_524288") { - __total_hash_count_cblocks++; - } - else { - __total_hash_count_gblocks++; - } - - uint64_t timestamp = microseconds(); - - if(timestamp - __hashrate_time > 5000000) { //we calculate hashrate every 5 seconds - __hashrate = __hashrate_hashcount / ((timestamp - __hashrate_time) / 1000000.0); - __hashrate_hashcount = 0; - __hashrate_time = timestamp; - } + // LOG(hash.hash); + __hashes_mutex.lock(); + __hashes.push_back(hash); + __hash_count++; + __hashrate_hashcount++; + if (hash.profile_name == "1_1_524288") { + __total_hash_count_cblocks++; + } + else { + __total_hash_count_gblocks++; + } + + uint64_t timestamp = microseconds(); + + if (timestamp - __hashrate_time > 5000000) { //we calculate hashrate every 5 seconds + __hashrate = __hashrate_hashcount / ((timestamp - __hashrate_time) / 1000000.0); + __hashrate_hashcount = 0; + __hashrate_time = timestamp; + } + + __hashes_mutex.unlock(); +} - __hashes_mutex.unlock(); +void hasher::_store_hash(const vector &hashes) { + if (hashes.size() == 0) return; + + __hashes_mutex.lock(); + __hashes.insert(__hashes.end(), hashes.begin(), hashes.end()); + __hash_count+=hashes.size(); + __hashrate_hashcount+=hashes.size(); + if (hashes[0].profile_name == "1_1_524288") { + __total_hash_count_cblocks+=hashes.size(); + } + else { + __total_hash_count_gblocks+=hashes.size(); + } + + uint64_t timestamp = microseconds(); + + if (timestamp - __hashrate_time > 5000000) { //we calculate hashrate every 5 seconds + __hashrate = __hashrate_hashcount / ((timestamp - __hashrate_time) / 1000000.0); + __hashrate_hashcount = 0; + __hashrate_time = timestamp; + } + + __hashes_mutex.unlock(); } vector hasher::get_hashers() { diff --git a/hash/hasher.h b/hash/hasher.h index d70cfb7..c6d53a0 100755 --- a/hash/hasher.h +++ b/hash/hasher.h @@ -63,7 +63,8 @@ class hasher { string _type; string _description; - void _store_hash(const hash_data &hash); + void _store_hash(const hash_data &hash); + void _store_hash(const vector &hashes); private: string __make_nonce();