Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove usleep(): usleep() is considered obsolete, move to nanosleep() #491

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,12 @@ static void * read_thd(void *d)
unsigned int i, nb_channels, nb = 0;
char buf[1024];
chtype *str;
struct timespec wait;
(void) row; /* Prevent warning */

usleep(100000);
wait.tv_sec = 0;
wait.tv_nsec = (100000 * 1000);
nanosleep(&wait, &wait);

if (selected < 0)
continue;
Expand Down Expand Up @@ -380,9 +383,13 @@ static void show_main_screen(struct iio_context *ctx)

while (!stop) {
int ret = activateCDKScroll(list, NULL);
struct timespec wait;
wait.tv_sec = 0;
wait.tv_nsec = (100000 * 1000);

stop = ret < 0;
selected = ret;
usleep(100000);
nanosleep(&wait, &wait);
}

pthread_join(thd, NULL);
Expand Down
9 changes: 6 additions & 3 deletions iiod/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,12 @@ static int open_dev_helper(struct parser_pdata *pdata, struct iio_device *dev,
* This is not pretty but it works.
*/
if (cyclic_retry) {
cyclic_retry--;
usleep(100);
goto retry;
struct timespec wait;
wait.tv_sec = 0;
wait.tv_nsec = (100 * 1000);
cyclic_retry--;
nanosleep(&wait, &wait);
goto retry;
}

ret = -EBUSY;
Expand Down
10 changes: 8 additions & 2 deletions tests/iio_stresstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,11 @@ static void *client_thread(void *data)
info->buffers[id]++;
buffer = iio_device_create_buffer(dev, info->buffer_size, false);
if (!buffer) {
struct timespec wait;
wait.tv_sec = 0;
wait.tv_nsec = (1 * 1000);
thread_err(id, errno, "iio_device_create_buffer failed");
usleep(1);
nanosleep(&wait, &wait);
continue;
}

Expand Down Expand Up @@ -571,7 +574,10 @@ int main(int argc, char **argv)
if (info.timeout && duration >= info.timeout) {
threads_running = false;
} else {
usleep(1000);
struct timespec wait;
wait.tv_sec = 0;
wait.tv_nsec = (1000 * 1000);
nanosleep(&wait, &wait);
}
}

Expand Down