Skip to content

Commit 612a0f9

Browse files
committed
posix: time.h: move to common libc time.h
1 parent 3a222b3 commit 612a0f9

File tree

16 files changed

+228
-123
lines changed

16 files changed

+228
-123
lines changed

include/zephyr/posix/mqueue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
#ifndef ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_
88
#define ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_
99

10+
#include <time.h>
11+
1012
#include <zephyr/kernel.h>
11-
#include <zephyr/posix/time.h>
1213
#include <zephyr/posix/fcntl.h>
1314
#include <zephyr/posix/signal.h>
1415
#include <zephyr/posix/sys/stat.h>

include/zephyr/posix/posix_features.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@
5656
#define _POSIX_CLOCK_SELECTION _POSIX_VERSION
5757
#endif
5858

59-
#ifdef CONFIG_POSIX_CPUTIME
60-
#define _POSIX_CPUTIME _POSIX_VERSION
61-
#endif
62-
6359
#ifdef CONFIG_POSIX_FSYNC
6460
#define _POSIX_FSYNC _POSIX_VERSION
6561
#endif
@@ -90,10 +86,6 @@
9086
#define _POSIX_MESSAGE_PASSING _POSIX_VERSION
9187
#endif
9288

93-
#ifdef CONFIG_POSIX_MONOTONIC_CLOCK
94-
#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
95-
#endif
96-
9789
/* #define _POSIX_PRIORITIZED_IO (-1L) */
9890

9991
#ifdef CONFIG_POSIX_PRIORITY_SCHEDULING

include/zephyr/posix/pthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include <stdlib.h>
1111
#include <string.h>
12+
#include <time.h>
1213

1314
#include <zephyr/kernel.h>
14-
#include <zephyr/posix/time.h>
1515
#include <zephyr/posix/unistd.h>
1616
#include <zephyr/posix/sched.h>
1717

include/zephyr/posix/semaphore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#ifndef ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_
77
#define ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_
88

9-
#include <zephyr/posix/time.h>
9+
#include <time.h>
10+
1011
#include <zephyr/posix/posix_types.h>
1112

1213
#ifdef __cplusplus

include/zephyr/posix/signal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef ZEPHYR_INCLUDE_POSIX_SIGNAL_H_
77
#define ZEPHYR_INCLUDE_POSIX_SIGNAL_H_
88

9+
#include <time.h>
10+
911
/* include posix_types.h before posix_features.h (here) to avoid build errors against newlib */
1012
#include <zephyr/posix/posix_types.h>
1113
#include "posix_features.h"

include/zephyr/posix/time.h

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,8 @@
11
/*
2-
* Copyright (c) 2018 Intel Corporation
2+
* Copyright The Zephyr Project Contributors
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_
7-
#define ZEPHYR_INCLUDE_POSIX_TIME_H_
86

9-
/* Read standard header. This may find <posix/time.h> since they
10-
* refer to the same file when include/posix is in the search path.
11-
*/
12-
#include <time.h>
13-
14-
#ifdef CONFIG_NEWLIB_LIBC
15-
/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */
16-
#include <newlib.h>
17-
18-
#ifdef __NEWLIB__
19-
/* Newever Newlib 3.x+ */
20-
#include <sys/timespec.h>
21-
#else /* __NEWLIB__ */
22-
/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h,
23-
* so mimic it here.
24-
*/
25-
#include <sys/types.h>
26-
#ifndef __timespec_defined
27-
28-
#ifdef __cplusplus
29-
extern "C" {
30-
#endif
31-
32-
struct timespec {
33-
time_t tv_sec;
34-
long tv_nsec;
35-
};
36-
37-
struct itimerspec {
38-
struct timespec it_interval; /* Timer interval */
39-
struct timespec it_value; /* Timer expiration */
40-
};
41-
42-
#ifdef __cplusplus
43-
}
44-
#endif
45-
46-
#endif /* __timespec_defined */
47-
#endif /* __NEWLIB__ */
48-
49-
#else /* CONFIG_NEWLIB_LIBC */
50-
/* Not Newlib */
51-
# if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC)
52-
# include <bits/types/struct_timespec.h>
53-
# include <bits/types/struct_itimerspec.h>
54-
# else
55-
# include <sys/timespec.h>
56-
# endif
57-
#endif /* CONFIG_NEWLIB_LIBC */
58-
59-
#include <zephyr/kernel.h>
60-
#include <errno.h>
61-
#include <zephyr/posix/posix_types.h>
62-
#include <zephyr/posix/signal.h>
63-
#include <zephyr/sys/clock.h>
64-
65-
#ifdef __cplusplus
66-
extern "C" {
67-
#endif
68-
69-
#ifndef CLOCK_REALTIME
70-
#define CLOCK_REALTIME SYS_CLOCK_REALTIME
71-
#endif
72-
73-
#ifndef CLOCK_PROCESS_CPUTIME_ID
74-
#define CLOCK_PROCESS_CPUTIME_ID 2
75-
#endif
76-
77-
#ifndef CLOCK_THREAD_CPUTIME_ID
78-
#define CLOCK_THREAD_CPUTIME_ID 3
79-
#endif
80-
81-
#ifndef CLOCK_MONOTONIC
82-
#define CLOCK_MONOTONIC SYS_CLOCK_MONOTONIC
83-
#endif
84-
85-
#ifndef TIMER_ABSTIME
86-
#define TIMER_ABSTIME SYS_TIMER_ABSTIME
87-
#endif
88-
89-
int clock_gettime(clockid_t clock_id, struct timespec *ts);
90-
int clock_getres(clockid_t clock_id, struct timespec *ts);
91-
int clock_settime(clockid_t clock_id, const struct timespec *ts);
92-
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
93-
/* Timer APIs */
94-
int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid);
95-
int timer_delete(timer_t timerid);
96-
struct itimerspec;
97-
int timer_gettime(timer_t timerid, struct itimerspec *its);
98-
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
99-
struct itimerspec *ovalue);
100-
int timer_getoverrun(timer_t timerid);
101-
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
102-
int clock_nanosleep(clockid_t clock_id, int flags,
103-
const struct timespec *rqtp, struct timespec *rmtp);
104-
105-
#ifdef __cplusplus
106-
}
107-
#endif
108-
109-
#else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */
110-
/* Read the toolchain header when <posix/time.h> finds itself on the
111-
* first attempt.
112-
*/
7+
/* This header will soon be deprecated. Please include <time.h> instead. */
1138
#include_next <time.h>
114-
#endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */

include/zephyr/posix/unistd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_
77
#define ZEPHYR_INCLUDE_POSIX_UNISTD_H_
88

9+
#include <time.h>
10+
911
#include <zephyr/posix/posix_types.h>
1012

1113
#ifdef CONFIG_POSIX_API

lib/libc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ config PICOLIBC
104104
select LIBC_ERRNO if THREAD_LOCAL_STORAGE
105105
select NEED_LIBC_MEM_PARTITION
106106
select TC_PROVIDES_POSIX_LIMIT_DEFS
107+
select TC_PROVIDES_POSIX_TIME_DEFS
107108
select TC_PROVIDES_POSIX_C_LANG_SUPPORT_R
108109
imply COMMON_LIBC_MALLOC
109110
imply COMMON_LIBC_ABORT
@@ -120,6 +121,7 @@ config NEWLIB_LIBC
120121
depends on NEWLIB_LIBC_SUPPORTED
121122
select NEED_LIBC_MEM_PARTITION
122123
select TC_PROVIDES_POSIX_C_LANG_SUPPORT_R
124+
select TC_PROVIDES_POSIX_TIME_DEFS
123125
imply POSIX_DEVICE_IO_ALIAS_CLOSE
124126
imply POSIX_DEVICE_IO_ALIAS_OPEN
125127
imply POSIX_DEVICE_IO_ALIAS_READ

0 commit comments

Comments
 (0)