From 82b2252ca510a52997912715cf40ddeac561e141 Mon Sep 17 00:00:00 2001 From: Robert Sacks Date: Thu, 23 Jul 2020 02:40:04 -0400 Subject: [PATCH] Replace usleep() usage with nanosleep() usleep() was declared obsolete in POSIX.1-2001 and removed in POSIX.1-2008. Replace its usage with nanosleep(). --- hash_pthreads.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hash_pthreads.c b/hash_pthreads.c index 78000c9..ec1a686 100644 --- a/hash_pthreads.c +++ b/hash_pthreads.c @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include /* read(), close() */ #include /* PRId64 etc. */ #include +#include /* nanosleep() */ #ifdef USE_OPENSSL #include /* SHA1() */ @@ -169,6 +170,10 @@ static void *print_progress(void *data) { struct queue *q = data; int err; + struct timespec t; + + t.tv_sec = PROGRESS_PERIOD / 1000000; + t.tv_nsec = PROGRESS_PERIOD % 1000000 * 1000; err = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); FATAL_IF(err, "cannot set thread cancel type: %s\n", strerror(err)); @@ -178,7 +183,7 @@ static void *print_progress(void *data) printf("\rHashed %u of %u pieces.", q->pieces_hashed, q->pieces); fflush(stdout); /* now sleep for PROGRESS_PERIOD microseconds */ - usleep(PROGRESS_PERIOD); + nanosleep(&t, NULL); } return NULL;