Skip to content

Commit d2b9ff6

Browse files
authored
Merge pull request #491 from analogdevicesinc/rgetz-move-to-nanosleep
remove usleep(): usleep() is considered obsolete, move to nanosleep()
2 parents 336c3c8 + 817d875 commit d2b9ff6

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

examples/iio-monitor.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ static void * read_thd(void *d)
162162
unsigned int i, nb_channels, nb = 0;
163163
char buf[1024];
164164
chtype *str;
165+
struct timespec wait;
165166
(void) row; /* Prevent warning */
166167

167-
usleep(100000);
168+
wait.tv_sec = 0;
169+
wait.tv_nsec = (100000 * 1000);
170+
nanosleep(&wait, &wait);
168171

169172
if (selected < 0)
170173
continue;
@@ -380,9 +383,13 @@ static void show_main_screen(struct iio_context *ctx)
380383

381384
while (!stop) {
382385
int ret = activateCDKScroll(list, NULL);
386+
struct timespec wait;
387+
wait.tv_sec = 0;
388+
wait.tv_nsec = (100000 * 1000);
389+
383390
stop = ret < 0;
384391
selected = ret;
385-
usleep(100000);
392+
nanosleep(&wait, &wait);
386393
}
387394

388395
pthread_join(thd, NULL);

iiod/ops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,12 @@ static int open_dev_helper(struct parser_pdata *pdata, struct iio_device *dev,
951951
* This is not pretty but it works.
952952
*/
953953
if (cyclic_retry) {
954-
cyclic_retry--;
955-
usleep(100);
956-
goto retry;
954+
struct timespec wait;
955+
wait.tv_sec = 0;
956+
wait.tv_nsec = (100 * 1000);
957+
cyclic_retry--;
958+
nanosleep(&wait, &wait);
959+
goto retry;
957960
}
958961

959962
ret = -EBUSY;

tests/iio_stresstest.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,11 @@ static void *client_thread(void *data)
318318
info->buffers[id]++;
319319
buffer = iio_device_create_buffer(dev, info->buffer_size, false);
320320
if (!buffer) {
321+
struct timespec wait;
322+
wait.tv_sec = 0;
323+
wait.tv_nsec = (1 * 1000);
321324
thread_err(id, errno, "iio_device_create_buffer failed");
322-
usleep(1);
325+
nanosleep(&wait, &wait);
323326
continue;
324327
}
325328

@@ -571,7 +574,10 @@ int main(int argc, char **argv)
571574
if (info.timeout && duration >= info.timeout) {
572575
threads_running = false;
573576
} else {
574-
usleep(1000);
577+
struct timespec wait;
578+
wait.tv_sec = 0;
579+
wait.tv_nsec = (1000 * 1000);
580+
nanosleep(&wait, &wait);
575581
}
576582
}
577583

0 commit comments

Comments
 (0)