doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_eal / unix / eal_unix_timer.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #include <time.h>
6
7 #include <rte_cycles.h>
8
9 void
10 rte_delay_us_sleep(unsigned int us)
11 {
12         struct timespec wait[2];
13         int ind = 0;
14
15         wait[0].tv_sec = 0;
16         if (us >= US_PER_S) {
17                 wait[0].tv_sec = us / US_PER_S;
18                 us -= wait[0].tv_sec * US_PER_S;
19         }
20         wait[0].tv_nsec = 1000 * us;
21
22         while (nanosleep(&wait[ind], &wait[1 - ind]) && errno == EINTR) {
23                 /*
24                  * Sleep was interrupted. Flip the index, so the 'remainder'
25                  * will become the 'request' for a next call.
26                  */
27                 ind = 1 - ind;
28         }
29 }