Skip to content

Commit 62ff77d

Browse files
committed
[libc][time] 重命名非标准libc函数 并 调整time.h定义位置
1 parent 0f48449 commit 62ff77d

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

components/libc/compilers/common/sys/time.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
extern "C" {
2020
#endif
2121

22+
/* timezone */
2223
#define DST_NONE 0 /* not on dst */
2324
#define DST_USA 1 /* USA style dst */
2425
#define DST_AUST 2 /* Australian style dst */
@@ -31,12 +32,21 @@ extern "C" {
3132
#define DST_TUR 9 /* Turkey */
3233
#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
3334

34-
#ifndef _TIMEVAL_DEFINED
35-
#define _TIMEVAL_DEFINED
35+
struct timezone {
36+
int tz_minuteswest; /* minutes west of Greenwich */
37+
int tz_dsttime; /* type of dst correction */
38+
};
39+
40+
void rt_tz_set(rt_int8_t tz);
41+
rt_int8_t rt_tz_get(void);
42+
rt_int8_t rt_tz_is_dst(void);
43+
3644
/*
3745
* Structure returned by gettimeofday(2) system call,
3846
* and used in other calls.
3947
*/
48+
#ifndef _TIMEVAL_DEFINED
49+
#define _TIMEVAL_DEFINED
4050
#if !(defined(_WIN32))
4151
struct timeval {
4252
long tv_sec; /* seconds */
@@ -45,18 +55,6 @@ struct timeval {
4555
#endif
4656
#endif /* _TIMEVAL_DEFINED */
4757

48-
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
49-
struct timespec {
50-
time_t tv_sec; /* seconds */
51-
long tv_nsec; /* and nanoseconds */
52-
};
53-
#endif
54-
55-
struct timezone {
56-
int tz_minuteswest; /* minutes west of Greenwich */
57-
int tz_dsttime; /* type of dst correction */
58-
};
59-
6058
int stime(const time_t *t);
6159
time_t timegm(struct tm * const t);
6260
int gettimeofday(struct timeval *tv, struct timezone *tz);
@@ -67,6 +65,14 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
6765

6866
#ifdef RT_USING_POSIX
6967
#include <sys/types.h>
68+
69+
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
70+
struct timespec {
71+
time_t tv_sec; /* seconds */
72+
long tv_nsec; /* and nanoseconds */
73+
};
74+
#endif
75+
7076
/* posix clock and timer */
7177
#define MILLISECOND_PER_SECOND 1000UL
7278
#define MICROSECOND_PER_SECOND 1000000UL
@@ -96,15 +102,9 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
96102
int clock_getres (clockid_t clockid, struct timespec *res);
97103
int clock_gettime (clockid_t clockid, struct timespec *tp);
98104
int clock_settime (clockid_t clockid, const struct timespec *tp);
99-
int clock_time_to_tick(const struct timespec *time);
105+
int rt_timespec_to_tick(const struct timespec *time);
100106
#endif /* RT_USING_POSIX */
101107

102-
103-
/* timezone APIs (Not standard LIBC APIs) */
104-
void rt_tz_set(rt_int8_t tz);
105-
rt_int8_t rt_tz_get(void);
106-
rt_int8_t rt_tz_is_dst(void);
107-
108108
#ifdef __cplusplus
109109
}
110110
#endif

components/libc/compilers/common/time.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ RTM_EXPORT(difftime);
465465
RTM_EXPORT(strftime);
466466

467467
#ifdef RT_USING_POSIX
468-
static struct timeval _timevalue;
469-
static int clock_time_system_init()
468+
static volatile struct timeval _timevalue;
469+
static int _rt_clock_time_system_init()
470470
{
471471
time_t time;
472472
rt_tick_t tick;
@@ -493,7 +493,7 @@ static int clock_time_system_init()
493493

494494
return 0;
495495
}
496-
INIT_COMPONENT_EXPORT(clock_time_system_init);
496+
INIT_COMPONENT_EXPORT(_rt_clock_time_system_init);
497497

498498
int clock_getres(clockid_t clockid, struct timespec *res)
499499
{
@@ -614,7 +614,7 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
614614
}
615615
RTM_EXPORT(clock_settime);
616616

617-
int clock_time_to_tick(const struct timespec *time)
617+
int rt_timespec_to_tick(const struct timespec *time)
618618
{
619619
int tick;
620620
int nsecond, second;
@@ -645,19 +645,19 @@ int clock_time_to_tick(const struct timespec *time)
645645

646646
return tick;
647647
}
648-
RTM_EXPORT(clock_time_to_tick);
648+
RTM_EXPORT(rt_timespec_to_tick);
649649

650650
#endif /* RT_USING_POSIX */
651651

652652

653-
/* timezone APIs (Not standard LIBC APIs) */
653+
/* timezone */
654654
#ifndef RT_LIBC_DEFAULT_TIMEZONE
655655
#define RT_LIBC_DEFAULT_TIMEZONE 8
656656
#endif
657657

658658
#include <rthw.h>
659659

660-
volatile static rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
660+
static volatile rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
661661

662662
void rt_tz_set(rt_int8_t tz)
663663
{
@@ -669,7 +669,14 @@ void rt_tz_set(rt_int8_t tz)
669669

670670
rt_int8_t rt_tz_get(void)
671671
{
672-
return rt_current_timezone;
672+
rt_int8_t tz;
673+
register rt_base_t level;
674+
675+
level = rt_hw_interrupt_disable();
676+
tz = rt_current_timezone;
677+
rt_hw_interrupt_enable(level);
678+
679+
return tz;
673680
}
674681

675682
rt_int8_t rt_tz_is_dst(void)

components/libc/pthreads/mqueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ ssize_t mq_timedreceive(mqd_t mqdes,
243243
return -1;
244244
}
245245

246-
tick = clock_time_to_tick(abs_timeout);
246+
tick = rt_timespec_to_tick(abs_timeout);
247247

248248
result = rt_mq_recv(mqdes->mq, msg_ptr, msg_len, tick);
249249
if (result == RT_EOK)

components/libc/pthreads/pthread_cond.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond,
222222
int timeout;
223223
rt_err_t result;
224224

225-
timeout = clock_time_to_tick(abstime);
225+
timeout = rt_timespec_to_tick(abstime);
226226
result = _pthread_cond_timedwait(cond, mutex, timeout);
227227
if (result == RT_EOK)
228228
return 0;

components/libc/pthreads/semaphore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
319319
return EINVAL;
320320

321321
/* calculate os tick */
322-
tick = clock_time_to_tick(abs_timeout);
322+
tick = rt_timespec_to_tick(abs_timeout);
323323

324324
result = rt_sem_take(sem->sem, tick);
325325
if (result == -RT_ETIMEOUT)

components/libc/signal/posix_signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info,
8383
if (timeout)
8484
{
8585
extern int clock_time_to_tick(const struct timespec *time);
86-
tick = clock_time_to_tick(timeout);
86+
tick = rt_timespec_to_tick(timeout);
8787
}
8888
#endif
8989

0 commit comments

Comments
 (0)