diff options
author | David Phillips <david@sighup.nz> | 2017-11-23 23:47:31 +1300 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2017-11-23 23:47:31 +1300 |
commit | a21ef15964b7a242303edb71180ab5f1f45165e5 (patch) | |
tree | d0df8ca65b0155e98f2a25c118fe7fb1478a5970 /sand-leek.c | |
parent | 0add7dea6763ce192b8afe6cc07b5c10cbbd4507 (diff) | |
download | sand-leek-a21ef15964b7a242303edb71180ab5f1f45165e5.tar.xz |
Fall back on CLOCK_REALTIME at compile-time with warn
Diffstat (limited to 'sand-leek.c')
-rw-r--r-- | sand-leek.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/sand-leek.c b/sand-leek.c index d18b806..d53e524 100644 --- a/sand-leek.c +++ b/sand-leek.c @@ -25,6 +25,13 @@ #define RSA_KEY_BITS 1024 +#ifdef CLOCK_MONOTONIC +#define SL_CLOCK_SOURCE CLOCK_MONOTONIC +#else +#warning "This platform has no CLOCK_MONOTONIC, falling back on crappy CLOCK_REALTIME" +#define SL_CLOCK_SOURCE CLOCK_REALTIME +#endif + static char *search; static char search_pad[16]; static unsigned char search_raw[10]; @@ -246,8 +253,8 @@ monitor_progress(unsigned long volatile *khashes, int thread_count) { unsigned long last_total_khashes = 0; double hashes_nice = 0; char *hashes_nice_unit = NULL; - struct timespec start = {}; - struct timespec now = {}; + struct timespec start = {0, 0}; + struct timespec now = {0, 0}; int seconds = 0; int minutes = 0; int hours = 0; @@ -262,7 +269,7 @@ monitor_progress(unsigned long volatile *khashes, int thread_count) { est_khashes = pow(32, search_len) / 1000; /* FIXME linux-only? Need a portable alternative or (shriek) ifdefs */ - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(SL_CLOCK_SOURCE, &start); loops = 0; /* loop while no thread as announced work end; we don't want to @@ -299,7 +306,7 @@ monitor_progress(unsigned long volatile *khashes, int thread_count) { } /* compute timestamp */ - clock_gettime(CLOCK_MONOTONIC, &now); + clock_gettime(SL_CLOCK_SOURCE, &now); delta = now.tv_sec - start.tv_sec; nice_time(delta, &seconds, &minutes, &hours, &days); |