Skip to content

Commit 7ab21b0

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 8da6a9b commit 7ab21b0

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,8 +36,9 @@
3636

3737
#include "config.h"
3838

39+
#include <chrono>
3940
#include <functional>
40-
#include <unistd.h>
41+
#include <thread>
4142

4243
#include "torrent/exceptions.h"
4344
#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
@@ -1,8 +1,9 @@
11
#include "config.h"
22

3+
#include <chrono>
34
#include <cstring>
45
#include <signal.h>
5-
#include <unistd.h>
6+
#include <thread>
67

78
#include "torrent/exceptions.h"
89
#include "torrent/poll.h"
@@ -60,7 +61,7 @@ thread_base::stop_thread_wait() {
6061
release_global_lock();
6162

6263
while (!is_inactive()) {
63-
usleep(1000);
64+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
6465
}
6566

6667
acquire_global_lock();
@@ -132,7 +133,7 @@ thread_base::event_loop(thread_base* thread) {
132133
}
133134

134135
// Add the sleep call when testing interrupts, etc.
135-
// usleep(50);
136+
// std::this_thread::sleep_for(std::chrono::microseconds(50));
136137

137138
int poll_flags = 0;
138139

0 commit comments

Comments
 (0)