[PATCH 2/2] posix: cond_timedwait remember and use clock from condattr

Gedare Bloom gedare at rtems.org
Thu Jun 23 20:59:14 UTC 2016


updates #2745
---
 cpukit/posix/include/rtems/posix/cond.h     | 1 +
 cpukit/posix/include/rtems/posix/condimpl.h | 4 +++-
 cpukit/posix/src/condinit.c                 | 2 +-
 cpukit/posix/src/condtimedwait.c            | 3 +++
 cpukit/posix/src/condwaitsupp.c             | 3 ++-
 cpukit/posix/src/mqueuetimedreceive.c       | 2 +-
 cpukit/posix/src/mqueuetimedsend.c          | 2 +-
 cpukit/posix/src/mutextimedlock.c           | 2 +-
 cpukit/posix/src/prwlocktimedrdlock.c       | 2 +-
 cpukit/posix/src/prwlocktimedwrlock.c       | 2 +-
 cpukit/posix/src/semtimedwait.c             | 2 +-
 cpukit/score/include/rtems/score/todimpl.h  | 2 ++
 cpukit/score/src/condition.c                | 4 ++--
 cpukit/score/src/coretodabsolutetimeout.c   | 9 +++++++--
 cpukit/score/src/mutex.c                    | 4 ++--
 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 4fa7de7..bbb80ef 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 dbeb6e1..70a0707 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 dde400f..e863dcd 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 6c0b14f..1b338c8 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 79f0f72..5fd504c 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 19e5430..f9b2730 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 ce178fa..3920a3f 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 c2f0078..cfc1827 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 c7f1600..b1a7c01 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 ad6af40..b047146 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 58d6e24..09028f4 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 f53e365..03f25b5 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 c388d94..691115d 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 6c9ffc2..fe74a6b 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 4b5127c..aad396e 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;
-- 
1.9.1




More information about the devel mailing list