Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright 2020 Mellanox Technologies, Ltd 3 : : */ 4 : : 5 : : #include <errno.h> 6 : : #include <time.h> 7 : : 8 : : #include <eal_export.h> 9 : : #include <rte_cycles.h> 10 : : 11 : : RTE_EXPORT_SYMBOL(rte_delay_us_sleep) 12 : : void 13 : 508 : rte_delay_us_sleep(unsigned int us) 14 : : { 15 : : struct timespec wait[2]; 16 : : int ind = 0; 17 : : 18 : 508 : wait[0].tv_sec = 0; 19 [ - + ]: 508 : if (us >= US_PER_S) { 20 : 0 : wait[0].tv_sec = us / US_PER_S; 21 : 0 : us -= wait[0].tv_sec * US_PER_S; 22 : : } 23 : 508 : wait[0].tv_nsec = 1000 * us; 24 : : 25 [ - + - - ]: 508 : while (nanosleep(&wait[ind], &wait[1 - ind]) && errno == EINTR) { 26 : : /* 27 : : * Sleep was interrupted. Flip the index, so the 'remainder' 28 : : * will become the 'request' for a next call. 29 : : */ 30 : : ind = 1 - ind; 31 : : } 32 : 508 : }