summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/compilers/common/sys/time.h1
-rw-r--r--components/libc/compilers/common/time.c34
-rw-r--r--components/libc/pthreads/pthread.c33
-rw-r--r--components/libc/pthreads/pthread_internal.h3
4 files changed, 36 insertions, 35 deletions
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h
index df5b4fae93..e4d60d2d11 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -86,6 +86,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz);
int clock_getres (clockid_t clockid, struct timespec *res);
int clock_gettime (clockid_t clockid, struct timespec *tp);
int clock_settime (clockid_t clockid, const struct timespec *tp);
+int clock_time_to_tick(const struct timespec *time);
#endif /* RT_USING_POSIX */
#ifdef __cplusplus
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index c73bb0f26c..c2fbd6f333 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -512,4 +512,38 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
return 0;
}
RTM_EXPORT(clock_settime);
+
+int clock_time_to_tick(const struct timespec *time)
+{
+ int tick;
+ int nsecond, second;
+ struct timespec tp;
+
+ RT_ASSERT(time != RT_NULL);
+
+ tick = RT_WAITING_FOREVER;
+ if (time != NULL)
+ {
+ /* get current tp */
+ clock_gettime(CLOCK_REALTIME, &tp);
+
+ if ((time->tv_nsec - tp.tv_nsec) < 0)
+ {
+ nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec);
+ second = time->tv_sec - tp.tv_sec - 1;
+ }
+ else
+ {
+ nsecond = time->tv_nsec - tp.tv_nsec;
+ second = time->tv_sec - tp.tv_sec;
+ }
+
+ tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND;
+ if (tick < 0) tick = 0;
+ }
+
+ return tick;
+}
+RTM_EXPORT(clock_time_to_tick);
+
#endif /* RT_USING_POSIX */
diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c
index cec76a9691..7430510bf2 100644
--- a/components/libc/pthreads/pthread.c
+++ b/components/libc/pthreads/pthread.c
@@ -688,36 +688,3 @@ int pthread_cancel(pthread_t thread)
return 0;
}
RTM_EXPORT(pthread_cancel);
-
-int clock_time_to_tick(const struct timespec *time)
-{
- int tick;
- int nsecond, second;
- struct timespec tp;
-
- RT_ASSERT(time != RT_NULL);
-
- tick = RT_WAITING_FOREVER;
- if (time != NULL)
- {
- /* get current tp */
- clock_gettime(CLOCK_REALTIME, &tp);
-
- if ((time->tv_nsec - tp.tv_nsec) < 0)
- {
- nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec);
- second = time->tv_sec - tp.tv_sec - 1;
- }
- else
- {
- nsecond = time->tv_nsec - tp.tv_nsec;
- second = time->tv_sec - tp.tv_sec;
- }
-
- tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND;
- if (tick < 0) tick = 0;
- }
-
- return tick;
-}
-RTM_EXPORT(clock_time_to_tick);
diff --git a/components/libc/pthreads/pthread_internal.h b/components/libc/pthreads/pthread_internal.h
index a6706ca091..240741e21a 100644
--- a/components/libc/pthreads/pthread_internal.h
+++ b/components/libc/pthreads/pthread_internal.h
@@ -13,6 +13,7 @@
#include <rtthread.h>
#include <pthread.h>
+#include <sys/time.h>
struct _pthread_cleanup
{
@@ -62,8 +63,6 @@ typedef struct _pthread_data _pthread_data_t;
_pthread_data_t *_pthread_get_data(pthread_t thread);
-int clock_time_to_tick(const struct timespec *time);
-
void posix_mq_system_init(void);
void posix_sem_system_init(void);
void pthread_key_system_init(void);