[PATCH 1/2] posix: refactor cond wait support to defer abstime conversion
Gedare Bloom
gedare at rtems.org
Thu Jun 23 20:59:13 UTC 2016
updates #2745
---
cpukit/posix/include/rtems/posix/condimpl.h | 3 +--
cpukit/posix/src/condtimedwait.c | 25 +------------------------
cpukit/posix/src/condwait.c | 3 +--
cpukit/posix/src/condwaitsupp.c | 29 +++++++++++++++++++++++++++--
4 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/cpukit/posix/include/rtems/posix/condimpl.h b/cpukit/posix/include/rtems/posix/condimpl.h
index 736f06b..dbeb6e1 100644
--- a/cpukit/posix/include/rtems/posix/condimpl.h
+++ b/cpukit/posix/include/rtems/posix/condimpl.h
@@ -134,8 +134,7 @@ int _POSIX_Condition_variables_Signal_support(
int _POSIX_Condition_variables_Wait_support(
pthread_cond_t *cond,
pthread_mutex_t *mutex,
- Watchdog_Interval timeout,
- bool already_timedout
+ const struct timespec *abstime
);
#ifdef __cplusplus
diff --git a/cpukit/posix/src/condtimedwait.c b/cpukit/posix/src/condtimedwait.c
index 1a2f5ff..6c0b14f 100644
--- a/cpukit/posix/src/condtimedwait.c
+++ b/cpukit/posix/src/condtimedwait.c
@@ -31,32 +31,9 @@ int pthread_cond_timedwait(
const struct timespec *abstime
)
{
- Watchdog_Interval ticks;
- bool already_timedout;
- TOD_Absolute_timeout_conversion_results status;
-
- /*
- * POSIX requires that blocking calls with timeouts that take
- * an absolute timeout must ignore issues with the absolute
- * time provided if the operation would otherwise succeed.
- * So we check the abstime provided, and hold on to whether it
- * is valid or not. If it isn't correct and in the future,
- * then we do a polling operation and convert the UNSATISFIED
- * status into the appropriate error.
- */
- already_timedout = false;
- status = _TOD_Absolute_timeout_to_ticks(abstime, &ticks);
- if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID )
- return EINVAL;
-
- if ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
- status == TOD_ABSOLUTE_TIMEOUT_IS_NOW )
- already_timedout = true;
-
return _POSIX_Condition_variables_Wait_support(
cond,
mutex,
- ticks,
- already_timedout
+ abstime
);
}
diff --git a/cpukit/posix/src/condwait.c b/cpukit/posix/src/condwait.c
index 22004f8..9a88287 100644
--- a/cpukit/posix/src/condwait.c
+++ b/cpukit/posix/src/condwait.c
@@ -32,7 +32,6 @@ int pthread_cond_wait(
return _POSIX_Condition_variables_Wait_support(
cond,
mutex,
- WATCHDOG_NO_TIMEOUT,
- false
+ NULL
);
}
diff --git a/cpukit/posix/src/condwaitsupp.c b/cpukit/posix/src/condwaitsupp.c
index b2ed367..79f0f72 100644
--- a/cpukit/posix/src/condwaitsupp.c
+++ b/cpukit/posix/src/condwaitsupp.c
@@ -30,8 +30,7 @@ THREAD_QUEUE_OBJECT_ASSERT( POSIX_Condition_variables_Control, Wait_queue );
int _POSIX_Condition_variables_Wait_support(
pthread_cond_t *cond,
pthread_mutex_t *mutex,
- Watchdog_Interval timeout,
- bool already_timedout
+ const struct timespec *abstime
)
{
POSIX_Condition_variables_Control *the_cond;
@@ -40,6 +39,9 @@ int _POSIX_Condition_variables_Wait_support(
int mutex_error;
Per_CPU_Control *cpu_self;
Thread_Control *executing;
+ Watchdog_Interval timeout;
+ bool already_timedout;
+ TOD_Absolute_timeout_conversion_results status;
if ( mutex == NULL ) {
return EINVAL;
@@ -51,6 +53,29 @@ int _POSIX_Condition_variables_Wait_support(
return EINVAL;
}
+ already_timedout = false;
+
+ if ( abstime != NULL ) {
+ /*
+ * POSIX requires that blocking calls with timeouts that take
+ * an absolute timeout must ignore issues with the absolute
+ * time provided if the operation would otherwise succeed.
+ * So we check the abstime provided, and hold on to whether it
+ * is valid or not. If it isn't correct and in the future,
+ * then we do a polling operation and convert the UNSATISFIED
+ * status into the appropriate error.
+ */
+ status = _TOD_Absolute_timeout_to_ticks( abstime, &timeout );
+ if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID )
+ return EINVAL;
+
+ if ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
+ status == TOD_ABSOLUTE_TIMEOUT_IS_NOW )
+ already_timedout = true;
+ } else {
+ timeout = WATCHDOG_NO_TIMEOUT;
+ }
+
_POSIX_Condition_variables_Acquire_critical( the_cond, &queue_context );
if (
--
1.9.1
More information about the devel
mailing list