Skip to content

Commit 38efa9b

Browse files
committed
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.
1 parent 9bbbee6 commit 38efa9b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/data/hash_queue.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636

3737
#include "config.h"
3838

39+
#include <chrono>
40+
#include <thread>
3941
#include <functional>
4042
#include <rak/functional.h>
41-
#include <unistd.h>
4243

4344
#include "torrent/exceptions.h"
4445
#include "torrent/data/download_data.h"
@@ -135,7 +136,7 @@ HashQueue::remove(HashQueueNode::id_type id) {
135136

136137
while ((done_itr = m_done_chunks.find(hash_chunk)) == m_done_chunks.end()) {
137138
pthread_mutex_unlock(&m_done_chunks_lock);
138-
usleep(100);
139+
std::this_thread::sleep_for(std::chrono::microseconds(100));
139140
pthread_mutex_lock(&m_done_chunks_lock);
140141
}
141142

src/torrent/utils/thread_base.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
#include "config.h"
3838

3939
#include <cstring>
40+
#include <chrono>
41+
#include <thread>
4042
#include <signal.h>
41-
#include <unistd.h>
4243

4344
#include "exceptions.h"
4445
#include "poll.h"
@@ -97,7 +98,7 @@ thread_base::stop_thread_wait() {
9798
release_global_lock();
9899

99100
while (!is_inactive()) {
100-
usleep(1000);
101+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
101102
}
102103

103104
acquire_global_lock();
@@ -161,7 +162,7 @@ thread_base::event_loop(thread_base* thread) {
161162
}
162163

163164
// Add the sleep call when testing interrupts, etc.
164-
// usleep(50);
165+
// std::this_thread::sleep_for(std::chrono::microseconds(50));
165166

166167
int poll_flags = 0;
167168

0 commit comments

Comments
 (0)