-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.cpp
38 lines (34 loc) · 1.04 KB
/
Context.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Created by zeke on 6/28/21.
//
#include "Context.h"
Context::Context(DBXHash* _hasher) {
this->hasher = _hasher;
}
void Context::operator()() {
{
Locker m(hasher->lock, hasher->signal);
assert(state == st_full);
state = st_hashing;
}
hashblock(hash, data, size);
// cout << block+1 << " " << hexify(hash) << " 0x" << std::hex << (uint64_t) hash << endl;
{
Locker m(hasher->lock, hasher->signal);
assert(state == st_hashing);
state = st_hashed;
hasher->window[block%hasher->threads] = this;
for (int i=0; i<hasher->threads; i++) {
int64_t a = hasher->block_complete;
Context* c = hasher->window[a%hasher->threads];
if (c == nullptr) break;
int64_t b = c->block;
assert(a == b);
SHA256_Update(&hasher->sha256, c->hash, DIGEST_SIZE);
hasher->block_complete++;
c->size = 0;
c->state = st_free;
hasher->window[a%hasher->threads] = nullptr;
}
}
}