diff --git a/include/posix/unistd.h b/include/posix/unistd.h index 7af86fb5227..e3c6b69dab0 100644 --- a/include/posix/unistd.h +++ b/include/posix/unistd.h @@ -10,39 +10,16 @@ extern "C" { #endif -#include_next - -#ifdef CONFIG_PTHREAD_IPC #include "sys/types.h" -/** - * @brief Sleep for a specified number of seconds. - * - * See IEEE 1003.1 - */ -static inline unsigned sleep(unsigned int seconds) -{ - k_sleep(K_SECONDS(seconds)); - return 0; -} -/** - * @brief Suspend execution for microsecond intervals. - * - * See IEEE 1003.1 - */ -static inline int usleep(useconds_t useconds) -{ - if (useconds < USEC_PER_MSEC) { - k_busy_wait(useconds); - } else { - k_sleep(useconds / USEC_PER_MSEC); - } +#ifndef __ZEPHYR__ +#include_next +#endif - return 0; -} +unsigned sleep(unsigned int seconds); +int usleep(useconds_t useconds); #endif #ifdef __cplusplus } -#endif #endif /* __POSIX_UNISTD_H__ */ diff --git a/kernel/posix/CMakeLists.txt b/kernel/posix/CMakeLists.txt index 0ecc735142e..88788086d1c 100644 --- a/kernel/posix/CMakeLists.txt +++ b/kernel/posix/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(kernel PRIVATE posix/pthread_barrier.c) target_sources(kernel PRIVATE posix/pthread.c) target_sources(kernel PRIVATE posix/pthread_sched.c) target_sources(kernel PRIVATE posix/clock.c) +target_sources(kernel PRIVATE posix/sleep.c) target_sources(kernel PRIVATE posix/timer.c) target_sources(kernel PRIVATE posix/pthread_rwlock.c) target_sources(kernel PRIVATE posix/semaphore.c) diff --git a/kernel/posix/sleep.c b/kernel/posix/sleep.c new file mode 100644 index 00000000000..6cbd36d52bd --- /dev/null +++ b/kernel/posix/sleep.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +/** + * @brief Sleep for a specified number of seconds. + * + * See IEEE 1003.1 + */ +unsigned sleep(unsigned int seconds) +{ + k_sleep(K_SECONDS(seconds)); + return 0; +} +/** + * @brief Suspend execution for microsecond intervals. + * + * See IEEE 1003.1 + */ +int usleep(useconds_t useconds) +{ + if (useconds < USEC_PER_MSEC) { + k_busy_wait(useconds); + } else { + k_sleep(useconds / USEC_PER_MSEC); + } + + return 0; +}