From 6c99ef73665a55072eeedd6e479653959153f5ca Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 23 Aug 2019 13:19:08 -0700 Subject: [PATCH] Replace usleep with C++11's sleep_for usleep is deprecated and replaced by nanosleep in POSIX 2008. sleep_for is standard C++11 and internally uses nanosleep. --- src/data/hash_queue.cc | 5 +++-- src/torrent/utils/thread_base.cc | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/data/hash_queue.cc b/src/data/hash_queue.cc index 3f54892b9..db54e0ce1 100644 --- a/src/data/hash_queue.cc +++ b/src/data/hash_queue.cc @@ -36,9 +36,10 @@ #include "config.h" +#include +#include #include #include -#include #include "torrent/exceptions.h" #include "torrent/data/download_data.h" @@ -135,7 +136,7 @@ HashQueue::remove(HashQueueNode::id_type id) { while ((done_itr = m_done_chunks.find(hash_chunk)) == m_done_chunks.end()) { pthread_mutex_unlock(&m_done_chunks_lock); - usleep(100); + std::this_thread::sleep_for(std::chrono::microseconds(100)); pthread_mutex_lock(&m_done_chunks_lock); } diff --git a/src/torrent/utils/thread_base.cc b/src/torrent/utils/thread_base.cc index 99d6355df..021adc313 100644 --- a/src/torrent/utils/thread_base.cc +++ b/src/torrent/utils/thread_base.cc @@ -1,8 +1,9 @@ #include "config.h" #include +#include +#include #include -#include #include "exceptions.h" #include "poll.h" @@ -61,7 +62,7 @@ thread_base::stop_thread_wait() { release_global_lock(); while (!is_inactive()) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } acquire_global_lock(); @@ -125,7 +126,7 @@ thread_base::event_loop(thread_base* thread) { } // Add the sleep call when testing interrupts, etc. - // usleep(50); + // std::this_thread::sleep_for(std::chrono::microseconds(50)); int poll_flags = 0;