summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/condwaitsupp.c
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2016-06-23 16:10:39 -0400
committerGedare Bloom <gedare@rtems.org>2016-07-25 12:44:47 -0400
commit127c20ebd7ec45be2849c82437ba5e33ebf1fd46 (patch)
tree73aca8b41311191c4ac98a110798913af2227281 /cpukit/posix/src/condwaitsupp.c
parentcpukit/rtems: fix return type mismatch for _TOD_To_seconds (diff)
downloadrtems-127c20ebd7ec45be2849c82437ba5e33ebf1fd46.tar.bz2
posix: refactor cond wait support to defer abstime conversion
updates #2745
Diffstat (limited to 'cpukit/posix/src/condwaitsupp.c')
-rw-r--r--cpukit/posix/src/condwaitsupp.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/cpukit/posix/src/condwaitsupp.c b/cpukit/posix/src/condwaitsupp.c
index b2ed367cb7..caa3a9af3d 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,32 @@ 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 {
+ _Thread_queue_Context_set_relative_timeout( &queue_context, timeout );
+ }
+ } else {
+ _Thread_queue_Context_set_no_timeout( &queue_context );
+ }
+
_POSIX_Condition_variables_Acquire_critical( the_cond, &queue_context );
if (
@@ -68,8 +96,6 @@ int _POSIX_Condition_variables_Wait_support(
if ( !already_timedout ) {
_Thread_queue_Context_set_expected_level( &queue_context, 2 );
- _Thread_queue_Context_set_timeout( &queue_context, timeout );
- _Thread_queue_Context_set_discipline( &queue_context, WATCHDOG_RELATIVE );
_Thread_queue_Enqueue_critical(
&the_cond->Wait_queue.Queue,
POSIX_CONDITION_VARIABLES_TQ_OPERATIONS,