aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-06-27 17:21:03 +1200
committerDavid Phillips <david@sighup.nz>2017-06-27 17:22:00 +1200
commita3e735c45f08a345435a845fa73a293946992b59 (patch)
tree939e2f7be0ccaba6a09a792d460d3a4f5e3bb8fb
parentf4629a55ed53acffb29208403e15be9a279b7a9f (diff)
downloadsand-leek-a3e735c45f08a345435a845fa73a293946992b59.tar.xz
Don't trample worker thread output with performance string
-rw-r--r--sand-leek.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/sand-leek.c b/sand-leek.c
index 37fe14c..e5cf227 100644
--- a/sand-leek.c
+++ b/sand-leek.c
@@ -207,15 +207,16 @@ die_usage(const char *argv0) {
void
monitor_progress(unsigned long volatile *khashes, int thread_count) {
+ int res = 0;
int loops = 0;
int i = 0;
unsigned long total_khashes = 0;
unsigned long last_total_khashes = 0;
loops = 0;
- while (sem_trywait(&working) && errno == EAGAIN) {
- sleep(1);
- loops++;
+ /* loop while no thread as announced work end; we don't want to
+ * trample its output on stderr */
+ while (!sem_getvalue(&working, &res) && res == 0) {
last_total_khashes = total_khashes;
total_khashes = 0;
/* approximate hashes per second */
@@ -227,6 +228,8 @@ monitor_progress(unsigned long volatile *khashes, int thread_count) {
(double)(total_khashes - last_total_khashes) / thread_count,
(double)total_khashes / loops,
((double)total_khashes / loops) / thread_count);
+ sleep(1);
+ loops++;
}
/* line feed to finish off carriage return from hashrate fprintf */