kernel: POSIX: Compatibility layer for POSIX clock APIs.
This patch provides POSIX clock APIs for POSIX 1003.1 PSE52 standard. Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
This commit is contained in:
parent
1f2e126d4d
commit
d50b1fe981
6 changed files with 96 additions and 17 deletions
|
@ -8,18 +8,7 @@
|
|||
#define __PTHREAD_H__
|
||||
|
||||
#include <kernel.h>
|
||||
#ifdef CONFIG_NEWLIB_LIBC
|
||||
#include <time.h>
|
||||
#else
|
||||
/* This should probably live somewhere else but Zephyr doesn't
|
||||
* currently have a stdc layer to provide it
|
||||
*/
|
||||
struct timespec {
|
||||
s32_t tv_sec;
|
||||
s32_t tv_nsec;
|
||||
};
|
||||
#endif /* CONFIG_NEWLIB_LIBC */
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "posix_sched.h"
|
||||
#include "unistd.h"
|
||||
|
@ -63,11 +52,6 @@ struct posix_thread {
|
|||
#define PTHREAD_CANCEL_ENABLE (0 << _PTHREAD_CANCEL_POS)
|
||||
#define PTHREAD_CANCEL_DISABLE (1 << _PTHREAD_CANCEL_POS)
|
||||
|
||||
static inline s32_t _ts_to_ms(const struct timespec *to)
|
||||
{
|
||||
return (to->tv_sec * 1000) + (to->tv_nsec / 1000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Declare a pthread condition variable
|
||||
*
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef __POSIX_TYPES_H__
|
||||
#define __POSIX_TYPES_H__
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -15,6 +14,7 @@ extern "C" {
|
|||
#include_next <sys/types.h>
|
||||
|
||||
#ifdef CONFIG_PTHREAD_IPC
|
||||
#include <kernel.h>
|
||||
|
||||
/* Thread attributes */
|
||||
typedef struct pthread_attr_t {
|
||||
|
@ -60,6 +60,9 @@ typedef struct pthread_barrierattr {
|
|||
} pthread_barrierattr_t;
|
||||
|
||||
/* time related attributes */
|
||||
#ifndef CONFIG_NEWLIB_LIBC
|
||||
typedef u32_t clockid_t;
|
||||
#endif /*CONFIG_NEWLIB_LIBC */
|
||||
typedef unsigned long useconds_t;
|
||||
|
||||
#endif /* CONFIG_PTHREAD_IPC */
|
||||
|
|
49
include/posix/time.h
Normal file
49
include/posix/time.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __POSIX_TIME_H__
|
||||
#define __POSIX_TIME_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NEWLIB_LIBC
|
||||
#include_next <time.h>
|
||||
#else
|
||||
struct timespec {
|
||||
s32_t tv_sec;
|
||||
s32_t tv_nsec;
|
||||
};
|
||||
#endif /* CONFIG_NEWLIB_LIBC */
|
||||
#include <kernel.h>
|
||||
#include <errno.h>
|
||||
#include "sys/types.h"
|
||||
|
||||
#define CLOCK_MONOTONIC 1
|
||||
|
||||
static inline s32_t _ts_to_ms(const struct timespec *to)
|
||||
{
|
||||
return (to->tv_sec * 1000) + (to->tv_nsec / 1000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set clock time.
|
||||
*
|
||||
* See IEEE 1003.1
|
||||
*/
|
||||
static inline int clock_settime(clockid_t clock_id, const struct timespec *ts)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int clock_gettime(clockid_t clock_id, struct timespec *ts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_TIME_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue