diff --git a/components/pthreads/SConscript b/components/pthreads/SConscript index 5f017aea1791086a197c269d29f2be3786a6f9b3..9fe796d225234dc30451c76f8386dbcddabb4cc9 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 4884d07fb8a8271f5420f32495105ecd663294bd..0000000000000000000000000000000000000000 --- 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 849f5348ecf7c450da34f7233bb09a922ccabd9e..a3cc2c7c73612dff78e434a5fa41120f45b48bb3 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 901b1bed5974bae3a22efb69694474b5980c857c..80df241d85eaa7f00b009fe7eb367aea3788f87c 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 9eb6c828f89f515e1fbd36e75f217d0deed43c7b..f548aef0b9eaacabad90f8cae8dacc5103397f7b 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 d737955dbefe411ca4d99bc2d03aee3a9a3d964e..235b35c316303d7261cd049a2e1212b0f30f47e0 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 47c745e69e4d7f618fecd5fd61167c97d290a7c8..cc0b512ac0e95b8f59f6f19dbcefce0b6812f132 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 f80e0f8ec640d897004033a07ae700102a0f0ff5..214f66b42f6b67c0d0d66d44d1441dd8db149e14 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;