diff options
Diffstat (limited to 'cpukit/posix')
-rw-r--r-- | cpukit/posix/Makefile.am | 21 | ||||
-rw-r--r-- | cpukit/posix/include/rtems/posix/cond.h | 57 | ||||
-rw-r--r-- | cpukit/posix/include/rtems/posix/condimpl.h | 132 | ||||
-rw-r--r-- | cpukit/posix/include/rtems/posix/config.h | 6 | ||||
-rw-r--r-- | cpukit/posix/preinstall.am | 12 | ||||
-rw-r--r-- | cpukit/posix/src/cond.c | 65 | ||||
-rw-r--r-- | cpukit/posix/src/conddestroy.c | 26 | ||||
-rw-r--r-- | cpukit/posix/src/condget.c | 30 | ||||
-rw-r--r-- | cpukit/posix/src/condinit.c | 62 | ||||
-rw-r--r-- | cpukit/posix/src/condsignalsupp.c | 35 | ||||
-rw-r--r-- | cpukit/posix/src/condwait.c | 21 | ||||
-rw-r--r-- | cpukit/posix/src/condwaitsupp.c | 27 |
12 files changed, 190 insertions, 304 deletions
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am index b69ca23132..99d1e7d08e 100644 --- a/cpukit/posix/Makefile.am +++ b/cpukit/posix/Makefile.am @@ -17,6 +17,7 @@ include_rtems_posix_HEADERS = include/rtems/posix/sigset.h ## Some POSIX threads features are needed all the time include_rtems_posix_HEADERS += include/rtems/posix/barrierimpl.h +include_rtems_posix_HEADERS += include/rtems/posix/condimpl.h include_rtems_posix_HEADERS += include/rtems/posix/key.h include_rtems_posix_HEADERS += include/rtems/posix/keyimpl.h include_rtems_posix_HEADERS += include/rtems/posix/config.h @@ -34,8 +35,6 @@ include_HEADERS += include/mqueue.h # include/rtems/posix include_rtems_posix_HEADERS += include/rtems/posix/aio_misc.h -include_rtems_posix_HEADERS += include/rtems/posix/cond.h -include_rtems_posix_HEADERS += include/rtems/posix/condimpl.h include_rtems_posix_HEADERS += include/rtems/posix/mmanimpl.h include_rtems_posix_HEADERS += include/rtems/posix/mqueue.h include_rtems_posix_HEADERS += include/rtems/posix/mqueueimpl.h @@ -72,6 +71,15 @@ libposix_a_SOURCES += src/barrierattrdestroy.c src/barrierattrgetpshared.c \ src/pbarrierdestroy.c src/pbarrierinit.c \ src/pbarrierwait.c +## CONDITION_VARIABLE_C_FILES +libposix_a_SOURCES += src/condattrdestroy.c \ + src/condattrinit.c \ + src/condattrgetpshared.c src/condattrsetpshared.c \ + src/condattrgetclock.c src/condattrsetclock.c \ + src/condbroadcast.c src/conddefaultattributes.c src/conddestroy.c \ + src/condinit.c src/condsignal.c src/condsignalsupp.c \ + src/condtimedwait.c src/condwait.c src/condwaitsupp.c + if HAS_PTHREADS libposix_a_SOURCES += src/pthreadatfork.c @@ -80,15 +88,6 @@ libposix_a_SOURCES += src/cancel.c \ src/cleanuppush.c src/setcancelstate.c \ src/setcanceltype.c src/testcancel.c -## CONDITION_VARIABLE_C_FILES -libposix_a_SOURCES += src/cond.c src/condattrdestroy.c \ - src/condattrinit.c \ - src/condattrgetpshared.c src/condattrsetpshared.c \ - src/condattrgetclock.c src/condattrsetclock.c \ - src/condbroadcast.c src/conddefaultattributes.c src/conddestroy.c \ - src/condinit.c src/condsignal.c src/condsignalsupp.c \ - src/condtimedwait.c src/condwait.c src/condwaitsupp.c src/condget.c - ## MEMORY_C_FILES libposix_a_SOURCES += src/mlockall.c libposix_a_SOURCES += src/mlock.c diff --git a/cpukit/posix/include/rtems/posix/cond.h b/cpukit/posix/include/rtems/posix/cond.h deleted file mode 100644 index 52b9a59929..0000000000 --- a/cpukit/posix/include/rtems/posix/cond.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file - * - * @brief POSIX Condition Variables Private Support - * - * This include file contains all the private support information for - * POSIX condition variables. - */ - -/* - * COPYRIGHT (c) 1989-2011. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#ifndef _RTEMS_POSIX_COND_H -#define _RTEMS_POSIX_COND_H - -#include <rtems/score/object.h> -#include <rtems/score/threadq.h> - -#include <pthread.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup POSIX_COND_VARS POSIX Condition Variables - * - * @ingroup POSIXAPI - * - */ -/**@{**/ - -/* - * Data Structure used to manage a POSIX condition variable - */ - -typedef struct { - Objects_Control Object; - Thread_queue_Control Wait_queue; - pthread_mutex_t *mutex; - clockid_t clock; -} POSIX_Condition_variables_Control; - -#ifdef __cplusplus -} -#endif - -/** @} */ - -#endif -/* end of include file */ diff --git a/cpukit/posix/include/rtems/posix/condimpl.h b/cpukit/posix/include/rtems/posix/condimpl.h index e9375c1075..66e09bf6d8 100644 --- a/cpukit/posix/include/rtems/posix/condimpl.h +++ b/cpukit/posix/include/rtems/posix/condimpl.h @@ -16,17 +16,29 @@ #ifndef _RTEMS_POSIX_CONDIMPL_H #define _RTEMS_POSIX_CONDIMPL_H - -#include <rtems/posix/cond.h> -#include <rtems/score/objectimpl.h> -#include <rtems/score/threadqimpl.h> #include <errno.h> +#include <pthread.h> + +#include <rtems/score/percpu.h> +#include <rtems/score/threadqimpl.h> #ifdef __cplusplus extern "C" { #endif +typedef struct { + unsigned long flags; + Thread_queue_Syslock_queue Queue; + pthread_mutex_t *mutex; +} POSIX_Condition_variables_Control; + +#define POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC 0x1UL + +#define POSIX_CONDITION_VARIABLES_FLAGS_MASK 0x1UL + +#define POSIX_CONDITION_VARIABLES_MAGIC 0x18dfb1feUL + /** * Constant to indicate condition variable does not currently have * a mutex assigned to it. @@ -37,86 +49,89 @@ extern "C" { #define POSIX_CONDITION_VARIABLE_OF_THREAD_QUEUE_QUEUE( queue ) \ RTEMS_CONTAINER_OF( \ - queue, POSIX_Condition_variables_Control, Wait_queue.Queue ) - -/** - * The following defines the information control block used to manage - * this class of objects. - */ -extern Objects_Information _POSIX_Condition_variables_Information; + queue, POSIX_Condition_variables_Control, Queue.Queue ) /** * The default condition variable attributes structure. */ extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes; +static inline POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get( + pthread_cond_t *cond +) +{ + return (POSIX_Condition_variables_Control *) cond; +} + RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Initialize( POSIX_Condition_variables_Control *the_cond, const pthread_condattr_t *the_attr ) { - _Thread_queue_Object_initialize( &the_cond->Wait_queue ); + unsigned long flags; + + _Thread_queue_Queue_initialize( &the_cond->Queue.Queue, NULL ); the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; - the_cond->clock = the_attr->clock; + + flags = (uintptr_t) the_cond ^ POSIX_CONDITION_VARIABLES_MAGIC; + flags &= ~POSIX_CONDITION_VARIABLES_FLAGS_MASK; + + if ( the_attr->clock == CLOCK_MONOTONIC ) { + flags |= POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC; + } + + the_cond->flags = flags; } RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Destroy( POSIX_Condition_variables_Control *the_cond ) { - _Thread_queue_Destroy( &the_cond->Wait_queue ); + the_cond->flags = ~the_cond->flags; } -RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Acquire_critical( - POSIX_Condition_variables_Control *the_cond, - Thread_queue_Context *queue_context +RTEMS_INLINE_ROUTINE clockid_t _POSIX_Condition_variables_Get_clock( + unsigned long flags ) { - _Thread_queue_Acquire_critical( &the_cond->Wait_queue, queue_context ); + if ( ( flags & POSIX_CONDITION_VARIABLES_CLOCK_MONOTONIC ) != 0 ) { + return CLOCK_MONOTONIC; + } + + return CLOCK_REALTIME; } -RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Release( +RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Condition_variables_Acquire( POSIX_Condition_variables_Control *the_cond, Thread_queue_Context *queue_context ) { - _Thread_queue_Release( &the_cond->Wait_queue, queue_context ); -} + ISR_Level level; + Thread_Control *executing; + + _Thread_queue_Context_ISR_disable( queue_context, level ); + _Thread_queue_Context_set_ISR_level( queue_context, level ); + executing = _Thread_Executing; + _Thread_queue_Queue_acquire_critical( + &the_cond->Queue.Queue, + &executing->Potpourri_stats, + &queue_context->Lock_context.Lock_context + ); -/** - * @brief POSIX Condition Variable Allocate - * - * This function allocates a condition variable control block from - * the inactive chain of free condition variable control blocks. - */ -RTEMS_INLINE_ROUTINE POSIX_Condition_variables_Control * - _POSIX_Condition_variables_Allocate( void ) -{ - return (POSIX_Condition_variables_Control *) - _Objects_Allocate( &_POSIX_Condition_variables_Information ); + return executing; } -/** - * @brief POSIX Condition Variable Free - * - * This routine frees a condition variable control block to the - * inactive chain of free condition variable control blocks. - */ -RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Free ( - POSIX_Condition_variables_Control *the_condition_variable +RTEMS_INLINE_ROUTINE void _POSIX_Condition_variables_Release( + POSIX_Condition_variables_Control *the_cond, + Thread_queue_Context *queue_context ) { - _Objects_Free( - &_POSIX_Condition_variables_Information, - &the_condition_variable->Object + _Thread_queue_Queue_release( + &the_cond->Queue.Queue, + &queue_context->Lock_context.Lock_context ); } -POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get( - pthread_cond_t *cond, - Thread_queue_Context *queue_context -); - /** * @brief Implements wake up version of the "signal" operation. * @@ -140,6 +155,27 @@ int _POSIX_Condition_variables_Wait_support( const struct timespec *abstime ); +bool _POSIX_Condition_variables_Auto_initialization( + POSIX_Condition_variables_Control *the_cond +); + +#define POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ) \ + do { \ + if ( ( the_cond ) == NULL ) { \ + return EINVAL; \ + } \ + flags = ( the_cond )->flags; \ + if ( \ + ( ( (uintptr_t) ( the_cond ) ^ POSIX_CONDITION_VARIABLES_MAGIC ) \ + & ~POSIX_CONDITION_VARIABLES_FLAGS_MASK ) \ + != ( flags & ~POSIX_CONDITION_VARIABLES_FLAGS_MASK ) \ + ) { \ + if ( !_POSIX_Condition_variables_Auto_initialization( the_cond ) ) { \ + return EINVAL; \ + } \ + } \ + } while ( 0 ) + #ifdef __cplusplus } #endif diff --git a/cpukit/posix/include/rtems/posix/config.h b/cpukit/posix/include/rtems/posix/config.h index 799eb62f03..2f5a5d7600 100644 --- a/cpukit/posix/include/rtems/posix/config.h +++ b/cpukit/posix/include/rtems/posix/config.h @@ -70,12 +70,6 @@ typedef struct { /** * This field contains the maximum number of POSIX API - * condition variables which are configured for this application. - */ - uint32_t maximum_condition_variables; - - /** - * This field contains the maximum number of POSIX API * timers which are configured for this application. */ uint32_t maximum_timers; diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am index 45d1c465b5..285999360f 100644 --- a/cpukit/posix/preinstall.am +++ b/cpukit/posix/preinstall.am @@ -31,6 +31,10 @@ $(PROJECT_INCLUDE)/rtems/posix/barrierimpl.h: include/rtems/posix/barrierimpl.h $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/barrierimpl.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/barrierimpl.h +$(PROJECT_INCLUDE)/rtems/posix/condimpl.h: include/rtems/posix/condimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/condimpl.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/condimpl.h + $(PROJECT_INCLUDE)/rtems/posix/key.h: include/rtems/posix/key.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/key.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/key.h @@ -80,14 +84,6 @@ $(PROJECT_INCLUDE)/rtems/posix/aio_misc.h: include/rtems/posix/aio_misc.h $(PROJ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/aio_misc.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/aio_misc.h -$(PROJECT_INCLUDE)/rtems/posix/cond.h: include/rtems/posix/cond.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/cond.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/cond.h - -$(PROJECT_INCLUDE)/rtems/posix/condimpl.h: include/rtems/posix/condimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/condimpl.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/condimpl.h - $(PROJECT_INCLUDE)/rtems/posix/mmanimpl.h: include/rtems/posix/mmanimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/mmanimpl.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/mmanimpl.h diff --git a/cpukit/posix/src/cond.c b/cpukit/posix/src/cond.c deleted file mode 100644 index 8ee57d89fd..0000000000 --- a/cpukit/posix/src/cond.c +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @file - * - * @brief Initialization Necessary for this Manager - * @ingroup POSIX_COND_VARS Condition Variables - */ - -/* - * COPYRIGHT (c) 1989-2008. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <pthread.h> -#include <errno.h> -#include <limits.h> - -#include <rtems/system.h> -#include <rtems/config.h> -#include <rtems/sysinit.h> -#include <rtems/score/watchdog.h> -#include <rtems/posix/condimpl.h> -#include <rtems/posix/muteximpl.h> - -Objects_Information _POSIX_Condition_variables_Information; - -/* - * _POSIX_Condition_variables_Manager_initialization - * - * This routine initializes all condition variable manager related data - * structures. - * - * Input parameters: NONE - * - * Output parameters: NONE - */ - -static void _POSIX_Condition_variables_Manager_initialization(void) -{ - _Objects_Initialize_information( - &_POSIX_Condition_variables_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_CONDITION_VARIABLES, /* object class */ - Configuration_POSIX_API.maximum_condition_variables, - /* maximum objects of this class */ - sizeof( POSIX_Condition_variables_Control ), - /* size of this object's control block */ - true, /* true if names for this object are strings */ - _POSIX_PATH_MAX, /* maximum length of each object's name */ - NULL /* Proxy extraction support callout */ - ); -} - -RTEMS_SYSINIT_ITEM( - _POSIX_Condition_variables_Manager_initialization, - RTEMS_SYSINIT_POSIX_CONDITION_VARIABLE, - RTEMS_SYSINIT_ORDER_MIDDLE -); diff --git a/cpukit/posix/src/conddestroy.c b/cpukit/posix/src/conddestroy.c index a2c8dc188f..63214362dc 100644 --- a/cpukit/posix/src/conddestroy.c +++ b/cpukit/posix/src/conddestroy.c @@ -24,36 +24,24 @@ * 11.4.2 Initializing and Destroying a Condition Variable, * P1003.1c/Draft 10, p. 87 */ -int pthread_cond_destroy( - pthread_cond_t *cond -) +int pthread_cond_destroy( pthread_cond_t *cond ) { POSIX_Condition_variables_Control *the_cond; + unsigned long flags; Thread_queue_Context queue_context; - _Objects_Allocator_lock(); - the_cond = _POSIX_Condition_variables_Get( cond, &queue_context ); + the_cond = _POSIX_Condition_variables_Get( cond ); + POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ); - if ( the_cond == NULL ) { - _Objects_Allocator_unlock(); - return EINVAL; - } - - _POSIX_Condition_variables_Acquire_critical( the_cond, &queue_context ); + _Thread_queue_Context_initialize( &queue_context ); + _POSIX_Condition_variables_Acquire( the_cond, &queue_context ); - if ( !_Thread_queue_Is_empty( &the_cond->Wait_queue.Queue ) ) { + if ( !_Thread_queue_Is_empty( &the_cond->Queue.Queue ) ) { _POSIX_Condition_variables_Release( the_cond, &queue_context ); - _Objects_Allocator_unlock(); return EBUSY; } - _Objects_Close( - &_POSIX_Condition_variables_Information, - &the_cond->Object - ); _POSIX_Condition_variables_Release( the_cond, &queue_context ); _POSIX_Condition_variables_Destroy( the_cond ); - _POSIX_Condition_variables_Free( the_cond ); - _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/condget.c b/cpukit/posix/src/condget.c deleted file mode 100644 index 5b086ef7c9..0000000000 --- a/cpukit/posix/src/condget.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2007. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <rtems/posix/condimpl.h> -#include <rtems/posix/posixapi.h> - -POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get( - pthread_cond_t *cond, - Thread_queue_Context *queue_context -) -{ - _POSIX_Get_object_body( - POSIX_Condition_variables_Control, - cond, - queue_context, - &_POSIX_Condition_variables_Information, - PTHREAD_COND_INITIALIZER, - pthread_cond_init - ); -} diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c index 8d3aa8e244..aab26aa9f7 100644 --- a/cpukit/posix/src/condinit.c +++ b/cpukit/posix/src/condinit.c @@ -21,6 +21,29 @@ #include <rtems/posix/condimpl.h> #include <rtems/posix/posixapi.h> +RTEMS_STATIC_ASSERT( + offsetof( POSIX_Condition_variables_Control, flags ) + == offsetof( pthread_cond_t, _flags ), + POSIX_CONDITION_VARIABLES_CONTROL_FLAGS +); + +RTEMS_STATIC_ASSERT( + offsetof( POSIX_Condition_variables_Control, mutex ) + == offsetof( pthread_cond_t, _mutex ), + POSIX_CONDITION_VARIABLES_CONTROL_COUNT +); + +RTEMS_STATIC_ASSERT( + offsetof( POSIX_Condition_variables_Control, Queue ) + == offsetof( pthread_cond_t, _Queue ), + POSIX_CONDITION_VARIABLES_CONTROL_QUEUE +); + +RTEMS_STATIC_ASSERT( + sizeof( POSIX_Condition_variables_Control ) == sizeof( pthread_cond_t ), + POSIX_CONDITION_VARIABLES_CONTROL_SIZE +); + /** * 11.4.2 Initializing and Destroying a Condition Variable, * P1003.1c/Draft 10, p. 87 @@ -30,41 +53,26 @@ int pthread_cond_init( const pthread_condattr_t *attr ) { - POSIX_Condition_variables_Control *the_cond; - const pthread_condattr_t *the_attr; + POSIX_Condition_variables_Control *the_cond; - if ( attr ) the_attr = attr; - else the_attr = &_POSIX_Condition_variables_Default_attributes; - - /* - * Be careful about attributes when global!!! - */ - - if ( !the_attr->is_initialized ) - return EINVAL; + the_cond = _POSIX_Condition_variables_Get( cond ); - if ( !_POSIX_Is_valid_pshared( the_attr->process_shared ) ) { + if ( the_cond == NULL ) { return EINVAL; } - the_cond = _POSIX_Condition_variables_Allocate(); - - if ( !the_cond ) { - _Objects_Allocator_unlock(); - return ENOMEM; + if ( attr == NULL ) { + attr = &_POSIX_Condition_variables_Default_attributes; } - _POSIX_Condition_variables_Initialize( the_cond, the_attr ); - - _Objects_Open_u32( - &_POSIX_Condition_variables_Information, - &the_cond->Object, - 0 - ); - - *cond = the_cond->Object.id; + if ( !attr->is_initialized ) { + return EINVAL; + } - _Objects_Allocator_unlock(); + if ( !_POSIX_Is_valid_pshared( attr->process_shared ) ) { + return EINVAL; + } + _POSIX_Condition_variables_Initialize( the_cond, attr ); return 0; } diff --git a/cpukit/posix/src/condsignalsupp.c b/cpukit/posix/src/condsignalsupp.c index e42476e1c4..1d9d4fc1ad 100644 --- a/cpukit/posix/src/condsignalsupp.c +++ b/cpukit/posix/src/condsignalsupp.c @@ -32,29 +32,30 @@ int _POSIX_Condition_variables_Signal_support( bool is_broadcast ) { - Thread_Control *the_thread; + POSIX_Condition_variables_Control *the_cond; + unsigned long flags; + const Thread_queue_Operations *operations; + Thread_queue_Heads *heads; - do { - POSIX_Condition_variables_Control *the_cond; - Thread_queue_Context queue_context; + the_cond = _POSIX_Condition_variables_Get( cond ); + POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ); + operations = POSIX_CONDITION_VARIABLES_TQ_OPERATIONS; - the_cond = _POSIX_Condition_variables_Get( cond, &queue_context ); + do { + Thread_queue_Context queue_context; - if ( the_cond == NULL ) { - return EINVAL; - } + _Thread_queue_Context_initialize( &queue_context ); + _POSIX_Condition_variables_Acquire( the_cond, &queue_context ); - _POSIX_Condition_variables_Acquire_critical( the_cond, &queue_context ); + heads = the_cond->Queue.Queue.heads; - the_thread = _Thread_queue_First_locked( - &the_cond->Wait_queue, - POSIX_CONDITION_VARIABLES_TQ_OPERATIONS - ); + if ( heads != NULL ) { + Thread_Control *the_thread; - if ( the_thread != NULL ) { + the_thread = ( *operations->first )( heads ); _Thread_queue_Extract_critical( - &the_cond->Wait_queue.Queue, - POSIX_CONDITION_VARIABLES_TQ_OPERATIONS, + &the_cond->Queue.Queue, + operations, the_thread, &queue_context ); @@ -62,7 +63,7 @@ int _POSIX_Condition_variables_Signal_support( the_cond->mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; _POSIX_Condition_variables_Release( the_cond, &queue_context ); } - } while ( is_broadcast && the_thread != NULL ); + } while ( is_broadcast && heads != NULL ); return 0; } diff --git a/cpukit/posix/src/condwait.c b/cpukit/posix/src/condwait.c index 9a88287d0d..9527077757 100644 --- a/cpukit/posix/src/condwait.c +++ b/cpukit/posix/src/condwait.c @@ -20,6 +20,27 @@ #include <rtems/posix/condimpl.h> +#include <string.h> + +bool _POSIX_Condition_variables_Auto_initialization( + POSIX_Condition_variables_Control *the_cond +) +{ + POSIX_Condition_variables_Control zero; + unsigned long flags; + + memset( &zero, 0, sizeof( zero ) ); + + if ( memcmp( the_cond, &zero, sizeof( *the_cond ) ) != 0 ) { + return false; + } + + flags = (uintptr_t) the_cond ^ POSIX_CONDITION_VARIABLES_MAGIC; + flags &= ~POSIX_CONDITION_VARIABLES_FLAGS_MASK; + the_cond->flags = flags; + return true; +} + /* * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 */ diff --git a/cpukit/posix/src/condwaitsupp.c b/cpukit/posix/src/condwaitsupp.c index 486bab879c..ceaa6eb1af 100644 --- a/cpukit/posix/src/condwaitsupp.c +++ b/cpukit/posix/src/condwaitsupp.c @@ -25,8 +25,6 @@ #include <rtems/score/status.h> #include <rtems/score/threaddispatch.h> -THREAD_QUEUE_OBJECT_ASSERT( POSIX_Condition_variables_Control, Wait_queue ); - static void _POSIX_Condition_variables_Enqueue_callout( Thread_queue_Queue *queue, Thread_Control *the_thread, @@ -58,6 +56,7 @@ int _POSIX_Condition_variables_Wait_support( ) { POSIX_Condition_variables_Control *the_cond; + unsigned long flags; Thread_queue_Context queue_context; int error; int mutex_error; @@ -66,16 +65,10 @@ int _POSIX_Condition_variables_Wait_support( bool already_timedout; TOD_Absolute_timeout_conversion_results status; - if ( mutex == NULL ) { - return EINVAL; - } - - the_cond = _POSIX_Condition_variables_Get( cond, &queue_context ); - - if ( the_cond == NULL ) { - return EINVAL; - } + the_cond = _POSIX_Condition_variables_Get( cond ); + POSIX_CONDITION_VARIABLES_VALIDATE_OBJECT( the_cond, flags ); + _Thread_queue_Context_initialize( &queue_context ); already_timedout = false; if ( abstime != NULL ) { @@ -88,8 +81,11 @@ int _POSIX_Condition_variables_Wait_support( * then we do a polling operation and convert the UNSATISFIED * status into the appropriate error. */ - _Assert( the_cond->clock ); - status = _TOD_Absolute_timeout_to_ticks(abstime, the_cond->clock, &timeout); + status = _TOD_Absolute_timeout_to_ticks( + abstime, + _POSIX_Condition_variables_Get_clock( flags ), + &timeout + ); if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID ) return EINVAL; @@ -103,7 +99,7 @@ int _POSIX_Condition_variables_Wait_support( _Thread_queue_Context_set_no_timeout( &queue_context ); } - _POSIX_Condition_variables_Acquire_critical( the_cond, &queue_context ); + executing = _POSIX_Condition_variables_Acquire( the_cond, &queue_context ); if ( the_cond->mutex != POSIX_CONDITION_VARIABLES_NO_MUTEX @@ -114,7 +110,6 @@ int _POSIX_Condition_variables_Wait_support( } the_cond->mutex = mutex; - executing = _Thread_Executing; if ( !already_timedout ) { _Thread_queue_Context_set_thread_state( @@ -126,7 +121,7 @@ int _POSIX_Condition_variables_Wait_support( _POSIX_Condition_variables_Enqueue_callout ); _Thread_queue_Enqueue( - &the_cond->Wait_queue.Queue, + &the_cond->Queue.Queue, POSIX_CONDITION_VARIABLES_TQ_OPERATIONS, executing, &queue_context |