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 <youvedeep.singh@intel.com>
This commit is contained in:
parent
aaa9cf2edd
commit
f762fdf482
3 changed files with 38 additions and 28 deletions
|
@ -10,39 +10,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
#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 <unistd.h>
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
unsigned sleep(unsigned int seconds);
|
||||
int usleep(useconds_t useconds);
|
||||
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __POSIX_UNISTD_H__ */
|
||||
|
|
|
@ -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)
|
||||
|
|
32
kernel/posix/sleep.c
Normal file
32
kernel/posix/sleep.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue