update time related function.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1091 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-11-22 09:52:06 +00:00
parent cb72c44e5a
commit cf85a6688f
8 changed files with 32 additions and 51 deletions

View File

@ -1,20 +1,7 @@
Import('RTT_ROOT') Import('RTT_ROOT')
from building import * from building import *
src = Split(''' src = Glob('*.c')
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
''')
CPPPATH = [RTT_ROOT + '/components/pthreads'] CPPPATH = [RTT_ROOT + '/components/pthreads']
group = DefineGroup('pthreads', src, depend = ['RT_USING_PTHREADS'], CPPPATH = CPPPATH) group = DefineGroup('pthreads', src, depend = ['RT_USING_PTHREADS'], CPPPATH = CPPPATH)

View File

@ -1,27 +0,0 @@
#include <rtthread.h>
#include "pthread_internal.h"
#include <time.h>
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;
}

View File

@ -1,7 +1,10 @@
#include "mqueue.h" #include "mqueue.h"
#include <stdargs.h>
#include "pthread_internal.h" #include "pthread_internal.h"
#include <stdarg.h>
#include <errno.h>
#include <sys/fcntl.h>
int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat,
struct mq_attr *omqstat) 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); rt_set_errno(EINVAL);
return -1; 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); result = rt_mq_recv(mqdes, msg_ptr, msg_len, tick);
if (result == RT_EOK) return msg_len; if (result == RT_EOK) return msg_len;
if (result == -RT_ETIMEOUT) if (result == -RT_ETIMEOUT)
rt_set_errno(ETIMEOUT); rt_set_errno(ETIMEDOUT);
else else
rt_set_errno(EBADMSG); 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) int mq_notify(mqd_t mqdes, const struct sigevent *notification)
{ {
rt_set_errno(-RT_ERROT); rt_set_errno(-RT_ERROR);
return -1; return -1;
} }
@ -145,6 +148,7 @@ int mq_unlink(const char *name)
return -1; return -1;
} }
/* delete this message queue */
rt_mq_delete(mq); rt_mq_delete(mq);
return 0; return 0;
} }

View File

@ -4,7 +4,8 @@
#include <rtthread.h> #include <rtthread.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <signal.h> #include <sys/signal.h>
#include <pthread.h>
typedef rt_mq_t mqd_t; typedef rt_mq_t mqd_t;
struct mq_attr struct mq_attr

View File

@ -237,5 +237,22 @@ int pthread_barrier_init(pthread_barrier_t *barrier,
int pthread_barrier_wait(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 #endif

View File

@ -166,11 +166,10 @@ int pthread_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t * mutex, pthread_mutex_t * mutex,
const struct timespec *abstime) const struct timespec *abstime)
{ {
rt_int32_t timeout; int timeout;
rt_err_t result; rt_err_t result;
timeout = abstime->tv_sec * RT_TICK_PER_SECOND + timeout = libc_time_to_tick(abstime);
abstime->tv_nsec * RT_TICK_PER_SECOND/1000000000;
result = _pthread_cond_timedwait(cond, mutex, timeout); result = _pthread_cond_timedwait(cond, mutex, timeout);
if (result == RT_EOK) return 0; if (result == RT_EOK) return 0;
if (result == -RT_ETIMEOUT) return ETIMEDOUT; if (result == -RT_ETIMEOUT) return ETIMEDOUT;

View File

@ -53,6 +53,6 @@ rt_inline _pthread_data_t* _pthread_get_data(pthread_t thread)
return (_pthread_data_t*)thread->user_data; 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 #endif

View File

@ -93,7 +93,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
if (!sem || !abs_timeout) return EINVAL; if (!sem || !abs_timeout) return EINVAL;
/* calculate os tick */ /* 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); result = rt_sem_take(sem, tick);
if (result == -RT_ETIMEOUT) return ETIMEDOUT; if (result == -RT_ETIMEOUT) return ETIMEDOUT;