summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2016-06-23 16:55:38 -0400
committerGedare Bloom <gedare@rtems.org>2016-06-23 16:59:02 -0400
commit195a75f026f927d03fbb746963df89415f0f1470 (patch)
tree1ded10c205c5ab96fb1bfbd50bff604ef892fc93
parente0e396d98af44583be031ab1b06e1ee4a019b6af (diff)
posix: cond_timedwait remember and use clock from condattrclock2
updates #2745
-rw-r--r--cpukit/posix/include/rtems/posix/cond.h1
-rw-r--r--cpukit/posix/include/rtems/posix/condimpl.h4
-rw-r--r--cpukit/posix/src/condinit.c2
-rw-r--r--cpukit/posix/src/condtimedwait.c3
-rw-r--r--cpukit/posix/src/condwaitsupp.c3
-rw-r--r--cpukit/posix/src/mqueuetimedreceive.c2
-rw-r--r--cpukit/posix/src/mqueuetimedsend.c2
-rw-r--r--cpukit/posix/src/mutextimedlock.c2
-rw-r--r--cpukit/posix/src/prwlocktimedrdlock.c2
-rw-r--r--cpukit/posix/src/prwlocktimedwrlock.c2
-rw-r--r--cpukit/posix/src/semtimedwait.c2
-rw-r--r--cpukit/score/include/rtems/score/todimpl.h2
-rw-r--r--cpukit/score/src/condition.c4
-rw-r--r--cpukit/score/src/coretodabsolutetimeout.c9
-rw-r--r--cpukit/score/src/mutex.c4
15 files changed, 29 insertions, 15 deletions
diff --git a/cpukit/posix/include/rtems/posix/cond.h b/cpukit/posix/include/rtems/posix/cond.h
index 4fa7de7525..bbb80ef362 100644
--- a/cpukit/posix/include/rtems/posix/cond.h
+++ b/cpukit/posix/include/rtems/posix/cond.h
@@ -44,6 +44,7 @@ typedef struct {
Objects_Control Object;
Thread_queue_Control Wait_queue;
pthread_mutex_t mutex;
+ clockid_t clock;
} POSIX_Condition_variables_Control;
#ifdef __cplusplus
diff --git a/cpukit/posix/include/rtems/posix/condimpl.h b/cpukit/posix/include/rtems/posix/condimpl.h
index dbeb6e1089..70a0707b8d 100644
--- a/cpukit/posix/include/rtems/posix/condimpl.h
+++ b/cpukit/posix/include/rtems/posix/condimpl.h
@@ -47,11 +47,13 @@ extern Objects_Information _POSIX_Condition_variables_Information;
extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes;
RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Initialize(
- POSIX_Condition_variables_Control *the_cond
+ POSIX_Condition_variables_Control *the_cond,
+ pthread_condattr_t *the_attr
)
{
_Thread_queue_Initialize( &the_cond->Wait_queue );
the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
+ the_cond->clock = the_attr->clock;
}
RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Destroy(
diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c
index dde400f58d..e863dcd183 100644
--- a/cpukit/posix/src/condinit.c
+++ b/cpukit/posix/src/condinit.c
@@ -51,7 +51,7 @@ int pthread_cond_init(
return ENOMEM;
}
- _POSIX_Condition_variables_Initialize( the_cond );
+ _POSIX_Condition_variables_Initialize( the_cond, the_attr );
_Objects_Open_u32(
&_POSIX_Condition_variables_Information,
diff --git a/cpukit/posix/src/condtimedwait.c b/cpukit/posix/src/condtimedwait.c
index 6c0b14f27b..1b338c8ae6 100644
--- a/cpukit/posix/src/condtimedwait.c
+++ b/cpukit/posix/src/condtimedwait.c
@@ -31,6 +31,9 @@ int pthread_cond_timedwait(
const struct timespec *abstime
)
{
+ if ( abstime == NULL ) {
+ return EINVAL; /* not specified */
+ }
return _POSIX_Condition_variables_Wait_support(
cond,
mutex,
diff --git a/cpukit/posix/src/condwaitsupp.c b/cpukit/posix/src/condwaitsupp.c
index 79f0f721e7..5fd504c1ff 100644
--- a/cpukit/posix/src/condwaitsupp.c
+++ b/cpukit/posix/src/condwaitsupp.c
@@ -65,7 +65,8 @@ int _POSIX_Condition_variables_Wait_support(
* then we do a polling operation and convert the UNSATISFIED
* status into the appropriate error.
*/
- status = _TOD_Absolute_timeout_to_ticks( abstime, &timeout );
+ _Assert( the_cond->clock );
+ status = _TOD_Absolute_timeout_to_ticks(abstime, the_cond->clock, &timeout);
if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID )
return EINVAL;
diff --git a/cpukit/posix/src/mqueuetimedreceive.c b/cpukit/posix/src/mqueuetimedreceive.c
index 19e5430ff2..f9b2730baa 100644
--- a/cpukit/posix/src/mqueuetimedreceive.c
+++ b/cpukit/posix/src/mqueuetimedreceive.c
@@ -76,7 +76,7 @@ ssize_t mq_timedreceive(
* TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
* then we should not wait.
*/
- status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
+ status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
do_wait = false;
diff --git a/cpukit/posix/src/mqueuetimedsend.c b/cpukit/posix/src/mqueuetimedsend.c
index ce178fa08d..3920a3fcc1 100644
--- a/cpukit/posix/src/mqueuetimedsend.c
+++ b/cpukit/posix/src/mqueuetimedsend.c
@@ -56,7 +56,7 @@ int mq_timedsend(
* TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
* then we should not wait.
*/
- status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
+ status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
do_wait = false;
diff --git a/cpukit/posix/src/mutextimedlock.c b/cpukit/posix/src/mutextimedlock.c
index c2f00785e2..cfc1827ae8 100644
--- a/cpukit/posix/src/mutextimedlock.c
+++ b/cpukit/posix/src/mutextimedlock.c
@@ -55,7 +55,7 @@ int pthread_mutex_timedlock(
* TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
* then we should not wait.
*/
- status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
+ status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
do_wait = false;
diff --git a/cpukit/posix/src/prwlocktimedrdlock.c b/cpukit/posix/src/prwlocktimedrdlock.c
index c7f16002fd..b1a7c01c76 100644
--- a/cpukit/posix/src/prwlocktimedrdlock.c
+++ b/cpukit/posix/src/prwlocktimedrdlock.c
@@ -47,7 +47,7 @@ int pthread_rwlock_timedrdlock(
* TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
* then we should not wait.
*/
- timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
+ timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
diff --git a/cpukit/posix/src/prwlocktimedwrlock.c b/cpukit/posix/src/prwlocktimedwrlock.c
index ad6af40788..b047146447 100644
--- a/cpukit/posix/src/prwlocktimedwrlock.c
+++ b/cpukit/posix/src/prwlocktimedwrlock.c
@@ -49,7 +49,7 @@ int pthread_rwlock_timedwrlock(
* TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
* then we should not wait.
*/
- timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
+ timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
diff --git a/cpukit/posix/src/semtimedwait.c b/cpukit/posix/src/semtimedwait.c
index 58d6e24ed9..09028f4d08 100644
--- a/cpukit/posix/src/semtimedwait.c
+++ b/cpukit/posix/src/semtimedwait.c
@@ -60,7 +60,7 @@ int sem_timedwait(
* TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
* then we should not wait.
*/
- status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
+ status = _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks );
if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
do_wait = false;
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index f53e36577d..03f25b5ae0 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -363,6 +363,7 @@ typedef enum {
* of corresponding clock ticks for use by the SuperCore.
*
* @param[in] abstime is a pointer to the timeout
+ * @param[in] clock is the time source to use for the timeout
* @param[out] ticks_out will contain the number of ticks
*
* @return This method returns the number of ticks in @a ticks_out
@@ -372,6 +373,7 @@ typedef enum {
*/
TOD_Absolute_timeout_conversion_results _TOD_Absolute_timeout_to_ticks(
const struct timespec *abstime,
+ clockid_t clock,
Watchdog_Interval *ticks_out
);
diff --git a/cpukit/score/src/condition.c b/cpukit/score/src/condition.c
index c388d9482d..691115db79 100644
--- a/cpukit/score/src/condition.c
+++ b/cpukit/score/src/condition.c
@@ -141,7 +141,7 @@ int _Condition_Wait_timed(
_Thread_queue_Context_initialize( &queue_context );
_ISR_lock_ISR_disable( &queue_context.Lock_context );
- switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
+ switch ( _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks ) ) {
case TOD_ABSOLUTE_TIMEOUT_INVALID:
_ISR_lock_ISR_enable( &queue_context.Lock_context );
return EINVAL;
@@ -204,7 +204,7 @@ int _Condition_Wait_recursive_timed(
_Thread_queue_Context_initialize( &queue_context );
_ISR_lock_ISR_disable( &queue_context.Lock_context );
- switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
+ switch ( _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks ) ) {
case TOD_ABSOLUTE_TIMEOUT_INVALID:
_ISR_lock_ISR_enable( &queue_context.Lock_context );
return EINVAL;
diff --git a/cpukit/score/src/coretodabsolutetimeout.c b/cpukit/score/src/coretodabsolutetimeout.c
index 6c9ffc22d5..fe74a6bbf2 100644
--- a/cpukit/score/src/coretodabsolutetimeout.c
+++ b/cpukit/score/src/coretodabsolutetimeout.c
@@ -25,13 +25,13 @@
*/
TOD_Absolute_timeout_conversion_results _TOD_Absolute_timeout_to_ticks(
const struct timespec *abstime,
+ clockid_t clock,
Watchdog_Interval *ticks_out
)
{
struct timespec current_time;
struct timespec difference;
-
/*
* Make sure there is always a value returned.
*/
@@ -46,7 +46,12 @@ TOD_Absolute_timeout_conversion_results _TOD_Absolute_timeout_to_ticks(
/*
* Is the absolute time in the past?
*/
- _TOD_Get_as_timespec( &current_time );
+ if ( clock == CLOCK_REALTIME ) {
+ _TOD_Get_as_timespec( &current_time );
+ } else {
+ _Assert( clock == CLOCK_MONOTONIC );
+ _TOD_Get_zero_based_uptime_as_timespec( &current_time );
+ }
if ( _Timespec_Less_than( abstime, &current_time ) )
return TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST;
diff --git a/cpukit/score/src/mutex.c b/cpukit/score/src/mutex.c
index 4b5127cda1..aad396ed9d 100644
--- a/cpukit/score/src/mutex.c
+++ b/cpukit/score/src/mutex.c
@@ -247,7 +247,7 @@ int _Mutex_Acquire_timed(
} else {
Watchdog_Interval ticks;
- switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
+ switch ( _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks ) ) {
case TOD_ABSOLUTE_TIMEOUT_INVALID:
_Mutex_Queue_release( mutex, &queue_context );
return EINVAL;
@@ -372,7 +372,7 @@ int _Mutex_recursive_Acquire_timed(
} else {
Watchdog_Interval ticks;
- switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) {
+ switch ( _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks ) ) {
case TOD_ABSOLUTE_TIMEOUT_INVALID:
_Mutex_Queue_release( &mutex->Mutex, &queue_context );
return EINVAL;