From 377fe9cbd81337374af7228e0b5c5bc787d08f35 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 1 May 2015 00:14:39 +0200 Subject: [PATCH] Callback will now be called only 100 times pes DAG creation --- ethash.h | 3 +++ internal.c | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ethash.h b/ethash.h index 50f4aaaca..9bb48fcf6 100644 --- a/ethash.h +++ b/ethash.h @@ -102,6 +102,9 @@ ethash_return_value_t ethash_light_compute( * It accepts an unsigned with which a progress of DAG calculation * can be displayed. If all goes well the callback should return 0. * If a non-zero value is returned then DAG generation will stop. + * Be advised. A progress value of 100 means that DAG creation is + * almost complete and that this function will soon return succesfully. + * It does not mean that the function has already had a succesfull return. * @return Newly allocated ethash_full handler or NULL in case of * ERRNOMEM or invalid parameters used for @ref ethash_compute_full_data() */ diff --git a/internal.c b/internal.c index b0991b9ea..eb075c9db 100644 --- a/internal.c +++ b/internal.c @@ -153,14 +153,17 @@ bool ethash_compute_full_data( (full_size % sizeof(node)) != 0) { return false; } + unsigned int const max_n = full_size / sizeof(node); node* full_nodes = mem; - double const progress_change = 1.0f / (full_size / sizeof(node)); + double const progress_change = 1.0f / max_n; double progress = 0.0f; // now compute full nodes - for (unsigned n = 0; n != (full_size / sizeof(node)); ++n) { + for (unsigned n = 0; n != max_n; ++n) { if (callback && - callback((unsigned int)(ceil(progress * 100.0f))) != 0) { - return false; + n % (max_n / 100) == 0 && + callback((unsigned int)(ceil(progress * 100.0f))) != 0) { + + return false; } progress += progress_change; ethash_calculate_dag_item(&(full_nodes[n]), n, light);