kernel: POSIX: Compatibility layer for POSIX timer APIs.
This patch provides POSIX timer APIs for POSIX 1003.1 PSE52 standard. Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
This commit is contained in:
parent
f0b678b03b
commit
8d040f1bcb
7 changed files with 297 additions and 5 deletions
44
include/posix/signal.h
Normal file
44
include/posix/signal.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef __POSIX_SIGNAL_H__
|
||||
#define __POSIX_SIGNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "sys/types.h"
|
||||
|
||||
#ifndef SIGEV_NONE
|
||||
#define SIGEV_NONE 1
|
||||
#endif
|
||||
|
||||
#ifndef SIGEV_SIGNAL
|
||||
#define SIGEV_SIGNAL 2
|
||||
#endif
|
||||
|
||||
#ifndef SIGEV_THREAD
|
||||
#define SIGEV_THREAD 3
|
||||
#endif
|
||||
|
||||
typedef union sigval {
|
||||
int sival_int;
|
||||
void *sival_ptr;
|
||||
} sigval;
|
||||
|
||||
typedef struct sigevent {
|
||||
int sigev_notify;
|
||||
int sigev_signo;
|
||||
sigval sigev_value;
|
||||
void (*sigev_notify_function)(sigval val);
|
||||
pthread_attr_t *sigev_notify_attributes;
|
||||
} sigevent;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __POSIX_TIME_H__ */
|
|
@ -60,6 +60,7 @@ typedef struct pthread_barrierattr {
|
|||
#ifndef CONFIG_NEWLIB_LIBC
|
||||
typedef u32_t clockid_t;
|
||||
#endif /*CONFIG_NEWLIB_LIBC */
|
||||
typedef unsigned long timer_t;
|
||||
typedef unsigned long useconds_t;
|
||||
|
||||
#endif /* CONFIG_PTHREAD_IPC */
|
||||
|
|
|
@ -14,19 +14,38 @@ extern "C" {
|
|||
#include_next <time.h>
|
||||
#else
|
||||
struct timespec {
|
||||
s32_t tv_sec;
|
||||
s32_t tv_nsec;
|
||||
signed int tv_sec;
|
||||
signed int tv_nsec;
|
||||
};
|
||||
|
||||
struct itimerspec {
|
||||
struct timespec it_interval; /* Timer interval */
|
||||
struct timespec it_value; /* Timer expiration */
|
||||
};
|
||||
#endif /* CONFIG_NEWLIB_LIBC */
|
||||
|
||||
#include <kernel.h>
|
||||
#include <errno.h>
|
||||
#include "sys/types.h"
|
||||
#include "signal.h"
|
||||
|
||||
#ifndef CLOCK_REALTIME
|
||||
#define CLOCK_REALTIME 0
|
||||
#endif
|
||||
|
||||
#ifndef CLOCK_MONOTONIC
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#endif
|
||||
|
||||
#define NSEC_PER_MSEC (NSEC_PER_USEC * USEC_PER_MSEC)
|
||||
|
||||
#ifndef TIMER_ABSTIME
|
||||
#define TIMER_ABSTIME 4
|
||||
#endif
|
||||
|
||||
static inline s32_t _ts_to_ms(const struct timespec *to)
|
||||
{
|
||||
return (to->tv_sec * 1000) + (to->tv_nsec / 1000000);
|
||||
return (to->tv_sec * MSEC_PER_SEC) + (to->tv_nsec / NSEC_PER_MSEC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,6 +60,12 @@ static inline int clock_settime(clockid_t clock_id, const struct timespec *ts)
|
|||
}
|
||||
|
||||
int clock_gettime(clockid_t clock_id, struct timespec *ts);
|
||||
/* Timer APIs */
|
||||
int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
|
||||
int timer_delete(timer_t timerid);
|
||||
int timer_gettime(timer_t timerid, struct itimerspec *its);
|
||||
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||
struct itimerspec *ovalue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue