aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-05-05 10:38:30 +1200
committerDavid Phillips <david@sighup.nz>2017-05-05 10:38:30 +1200
commit621aef78ae346e584204b8211fe2809ac5eb930b (patch)
tree1949db93229df45b77bbc48d4a984240fff099d7
parent8ca8230a72bd72ae1ae2b522df15d12c8fd7aa60 (diff)
downloadsand-leek-621aef78ae346e584204b8211fe2809ac5eb930b.tar.xz
Refactor monitor loop to own function
-rw-r--r--sand-leek.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/sand-leek.c b/sand-leek.c
index 690da62..d199fcc 100644
--- a/sand-leek.c
+++ b/sand-leek.c
@@ -234,16 +234,38 @@ die_usage(const char *argv0) {
exit(1);
}
+void
+monitor_progress(unsigned long volatile *khash_count, int thread_count) {
+ int loops = 0;
+ int i = 0;
+ unsigned long khashes = 0;
+
+ loops = 0;
+ while (sem_trywait(&working) && errno == EAGAIN) {
+ sleep(1);
+ loops++;
+ khashes = 0;
+ /* approximate hashes per second */
+ for (i = 0; i < thread_count; i++) {
+ khashes += khash_count[i];
+ }
+ fprintf(stderr, "Average rate: %.2f kH/s (%.2f kH/s/thread)\r",
+ (double)khashes / loops,
+ ((double)khashes / loops) / thread_count);
+ }
+
+ /* line feed to finish off carriage return from hashrate fprintf */
+ fputc('\n', stderr);
+}
+
int
main(int argc, char **argv) {
int opt = '\0';
int thread_count = 1;
- int loops = 0;
int i = 0;
size_t offset = 0;
pthread_t *workers = NULL;
unsigned long volatile *khash_count = NULL;
- unsigned long khashes = 0;
while ((opt = getopt(argc, argv, "t:s:")) != -1) {
switch (opt) {
@@ -297,23 +319,7 @@ main(int argc, char **argv) {
}
}
- /* workers started; wait on one to finish */
- loops = 0;
- while (sem_trywait(&working) && errno == EAGAIN) {
- sleep(1);
- loops++;
- khashes = 0;
- /* approximate hashes per second */
- for (i = 0; i < thread_count; i++) {
- khashes += khash_count[i];
- }
- fprintf(stderr, "Average rate: %.2f kH/s (%.2f kH/s/thread)\r",
- (double)khashes / loops,
- ((double)khashes / loops) / thread_count);
- }
-
- /* line feed to finish off carriage return from hashrate fprintf */
- fputc('\n', stderr);
+ monitor_progress(khash_count, thread_count);
for (i = 0; i < thread_count; i++) {
pthread_join(workers[i], NULL);