From cf85a6688f966500d6782b499945d0b435037c04 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Mon, 22 Nov 2010 09:52:06 +0000 Subject: [PATCH] update time related function. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1091 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/pthreads/SConscript | 15 +------------- components/pthreads/clock_time.c | 27 -------------------------- components/pthreads/mqueue.c | 12 ++++++++---- components/pthreads/mqueue.h | 3 ++- components/pthreads/pthread.h | 17 ++++++++++++++++ components/pthreads/pthread_cond.c | 5 ++--- components/pthreads/pthread_internal.h | 2 +- components/pthreads/semaphore.c | 2 +- 8 files changed, 32 insertions(+), 51 deletions(-) delete mode 100644 components/pthreads/clock_time.c diff --git a/components/pthreads/SConscript b/components/pthreads/SConscript index 5f017aea17..9fe796d225 100644 --- a/components/pthreads/SConscript +++ b/components/pthreads/SConscript @@ -1,20 +1,7 @@ Import('RTT_ROOT') from building import * -src = Split(''' -clock_time.c -pthread.c -pthread_attr.c -pthread_barrier.c -pthread_cond.c -pthread_internal.c -pthread_mutex.c -pthread_rwlock.c -pthread_spin.c -pthread_tls.c -sched.c -semaphore.c -''') +src = Glob('*.c') CPPPATH = [RTT_ROOT + '/components/pthreads'] group = DefineGroup('pthreads', src, depend = ['RT_USING_PTHREADS'], CPPPATH = CPPPATH) diff --git a/components/pthreads/clock_time.c b/components/pthreads/clock_time.c deleted file mode 100644 index 4884d07fb8..0000000000 --- a/components/pthreads/clock_time.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include "pthread_internal.h" -#include - -int clock_getres(clockid_t clock_id, struct timespec *res) -{ - if ((clock_id != CLOCK_REALTIME) || (res == RT_NULL)) - { - rt_set_errno(EINVAL); - return -1; - } - - res->tv_sec = 0; - res->tv_nsec = NSEC_PER_TICK; - - return 0; -} - -int clock_gettime(clockid_t clock_id, struct timespec *tp) -{ - return 0; -} - -int clock_settime(clockid_t clock_id, const struct timespec *tp) -{ - return 0; -} diff --git a/components/pthreads/mqueue.c b/components/pthreads/mqueue.c index 849f5348ec..a3cc2c7c73 100644 --- a/components/pthreads/mqueue.c +++ b/components/pthreads/mqueue.c @@ -1,7 +1,10 @@ #include "mqueue.h" -#include #include "pthread_internal.h" +#include +#include +#include + int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat) { @@ -103,13 +106,13 @@ ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, rt_set_errno(EINVAL); return -1; } - tick = time_to_tick(abs_timeout); + tick = libc_time_to_tick(abs_timeout); result = rt_mq_recv(mqdes, msg_ptr, msg_len, tick); if (result == RT_EOK) return msg_len; if (result == -RT_ETIMEOUT) - rt_set_errno(ETIMEOUT); + rt_set_errno(ETIMEDOUT); else rt_set_errno(EBADMSG); @@ -125,7 +128,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_ int mq_notify(mqd_t mqdes, const struct sigevent *notification) { - rt_set_errno(-RT_ERROT); + rt_set_errno(-RT_ERROR); return -1; } @@ -145,6 +148,7 @@ int mq_unlink(const char *name) return -1; } + /* delete this message queue */ rt_mq_delete(mq); return 0; } diff --git a/components/pthreads/mqueue.h b/components/pthreads/mqueue.h index 901b1bed59..80df241d85 100644 --- a/components/pthreads/mqueue.h +++ b/components/pthreads/mqueue.h @@ -4,7 +4,8 @@ #include #include #include -#include +#include +#include typedef rt_mq_t mqd_t; struct mq_attr diff --git a/components/pthreads/pthread.h b/components/pthreads/pthread.h index 9eb6c828f8..f548aef0b9 100644 --- a/components/pthreads/pthread.h +++ b/components/pthreads/pthread.h @@ -237,5 +237,22 @@ int pthread_barrier_init(pthread_barrier_t *barrier, int pthread_barrier_wait(pthread_barrier_t *barrier); +/* Signal Generation and Delivery, P1003.1b-1993, p. 63 + NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and + sigev_notify_attributes to the sigevent structure. */ +union sigval { + int sival_int; /* Integer signal value */ + void *sival_ptr; /* Pointer signal value */ +}; + +struct sigevent { + int sigev_notify; /* Notification type */ + int sigev_signo; /* Signal number */ + union sigval sigev_value; /* Signal value */ + void (*sigev_notify_function)( union sigval ); + /* Notification function */ + pthread_attr_t *sigev_notify_attributes; /* Notification Attributes */ +}; + #endif diff --git a/components/pthreads/pthread_cond.c b/components/pthreads/pthread_cond.c index d737955dbe..235b35c316 100644 --- a/components/pthreads/pthread_cond.c +++ b/components/pthreads/pthread_cond.c @@ -166,11 +166,10 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t * mutex, const struct timespec *abstime) { - rt_int32_t timeout; + int timeout; rt_err_t result; - timeout = abstime->tv_sec * RT_TICK_PER_SECOND + - abstime->tv_nsec * RT_TICK_PER_SECOND/1000000000; + timeout = libc_time_to_tick(abstime); result = _pthread_cond_timedwait(cond, mutex, timeout); if (result == RT_EOK) return 0; if (result == -RT_ETIMEOUT) return ETIMEDOUT; diff --git a/components/pthreads/pthread_internal.h b/components/pthreads/pthread_internal.h index 47c745e69e..cc0b512ac0 100644 --- a/components/pthreads/pthread_internal.h +++ b/components/pthreads/pthread_internal.h @@ -53,6 +53,6 @@ rt_inline _pthread_data_t* _pthread_get_data(pthread_t thread) return (_pthread_data_t*)thread->user_data; } -#define NSEC_PER_TICK (1000000000UL/RT_TICK_PER_SECOND) +extern int libc_time_to_tick(const struct timespec *time); #endif diff --git a/components/pthreads/semaphore.c b/components/pthreads/semaphore.c index f80e0f8ec6..214f66b42f 100644 --- a/components/pthreads/semaphore.c +++ b/components/pthreads/semaphore.c @@ -93,7 +93,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout) if (!sem || !abs_timeout) return EINVAL; /* calculate os tick */ - tick = abs_timeout->tv_sec/RT_TICK_PER_SECOND + (abs_timeout->tv_nsec/1000) * (1000/RT_TICK_PER_SECOND); + tick = libc_time_to_tick(abs_timeout); result = rt_sem_take(sem, tick); if (result == -RT_ETIMEOUT) return ETIMEDOUT; -- GitLab