From f762fdf4828f1c530cc0aac352405d93521fb79c Mon Sep 17 00:00:00 2001 From: Youvedeep Singh Date: Tue, 27 Mar 2018 13:54:01 +0530 Subject: [PATCH] kernel: posix: move sleep and usleep functions into c file. Currently sleep and usleep functions are into unistd.h file. unistd includes toold chain secific unistd.h file and this file too has declaration for these functions. This is in conflict when posix specific unistd.h is included. Signed-off-by: Youvedeep Singh --- include/posix/unistd.h | 33 +++++---------------------------- kernel/posix/CMakeLists.txt | 1 + kernel/posix/sleep.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 kernel/posix/sleep.c 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; +}