Skip to content

Commit

Permalink
Small fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanadnan committed Aug 29, 2018
1 parent c0a8890 commit 980ffee
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
6 changes: 4 additions & 2 deletions hash/gpu/gpu_hasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<hash_data> stored_hashes;
for(vector<string>::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);
Expand Down
65 changes: 45 additions & 20 deletions hash/hasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,52 @@ vector<hash_data> 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<hash_data> &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 *> hasher::get_hashers() {
Expand Down
3 changes: 2 additions & 1 deletion hash/hasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<hash_data> &hashes);

private:
string __make_nonce();
Expand Down

0 comments on commit 980ffee

Please sign in to comment.