mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-18 04:00:03 +02:00
key_search: refactor into a KeySearch class.
This commit is contained in:
parent
418949f26f
commit
35bb2302dd
4 changed files with 96 additions and 29 deletions
|
|
@ -15,7 +15,7 @@ unsigned int g_count;
|
|||
std::mutex g_count_mtx;
|
||||
|
||||
// Thread process.
|
||||
static void _mt_search(const strlist_t& word_list) {
|
||||
static void _thr_proc(const strlist_t& word_list) {
|
||||
|
||||
struct ec_keypair pair;
|
||||
|
||||
|
|
@ -43,18 +43,16 @@ static void _mt_search(const strlist_t& word_list) {
|
|||
}
|
||||
}
|
||||
|
||||
void key_search_mt(const strlist_t& word_list, size_t n, size_t n_threads) {
|
||||
void KeySearch::setThreadCount(size_t num)
|
||||
{
|
||||
m_threads = num;
|
||||
}
|
||||
|
||||
void KeySearch::_search_mt(size_t n)
|
||||
{
|
||||
std::vector<std::thread> t;
|
||||
|
||||
// Not enough threads passed in by caller.
|
||||
if (n_threads < 2) {
|
||||
// Just use linear function.
|
||||
key_search(word_list, n);
|
||||
return;
|
||||
}
|
||||
|
||||
t.resize(n_threads - 1);
|
||||
t.resize(m_threads - 1);
|
||||
|
||||
// Setup global variables for the threads.
|
||||
g_max = n;
|
||||
|
|
@ -62,11 +60,11 @@ void key_search_mt(const strlist_t& word_list, size_t n, size_t n_threads) {
|
|||
|
||||
// Launch them.
|
||||
for(int i = 0; i < t.size(); i++) {
|
||||
t[i] = std::thread(_mt_search, word_list);
|
||||
t[i] = std::thread(_thr_proc, m_words);
|
||||
}
|
||||
|
||||
// Use main thread for 1 search
|
||||
_mt_search(word_list);
|
||||
_thr_proc(m_words);
|
||||
|
||||
// Wait for all threads to compelete.
|
||||
for(int i = 0; i < t.size(); i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue