From 5222488573e3ba8c2eceffe29f878a73a3a81694 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 26 Sep 2017 07:49:17 +0200 Subject: posix: Implement self-contained POSIX condvar POSIX condition variables are now available in all configurations and no longer depend on --enable-posix. Update #2514. Update #3113. --- cpukit/libcsupport/include/rtems/libcsupport.h | 1 - cpukit/libcsupport/src/resource_snapshot.c | 2 - cpukit/posix/Makefile.am | 21 ++-- cpukit/posix/include/rtems/posix/cond.h | 57 ----------- cpukit/posix/include/rtems/posix/condimpl.h | 132 ++++++++++++++++--------- cpukit/posix/include/rtems/posix/config.h | 6 -- cpukit/posix/preinstall.am | 12 +-- cpukit/posix/src/cond.c | 65 ------------ cpukit/posix/src/conddestroy.c | 26 ++--- cpukit/posix/src/condget.c | 30 ------ cpukit/posix/src/condinit.c | 62 +++++++----- cpukit/posix/src/condsignalsupp.c | 35 +++---- cpukit/posix/src/condwait.c | 21 ++++ cpukit/posix/src/condwaitsupp.c | 27 +++-- cpukit/rtems/src/rtemsobjectgetapiclassname.c | 1 - cpukit/sapi/include/confdefs.h | 63 ------------ cpukit/sapi/src/posixapi.c | 33 +++++++ cpukit/score/include/rtems/score/objectimpl.h | 1 - cpukit/score/include/rtems/sysinit.h | 1 - 19 files changed, 223 insertions(+), 373 deletions(-) delete mode 100644 cpukit/posix/include/rtems/posix/cond.h delete mode 100644 cpukit/posix/src/cond.c delete mode 100644 cpukit/posix/src/condget.c (limited to 'cpukit') diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h index 3246209bad..080fee471d 100644 --- a/cpukit/libcsupport/include/rtems/libcsupport.h +++ b/cpukit/libcsupport/include/rtems/libcsupport.h @@ -111,7 +111,6 @@ typedef struct { } rtems_resource_rtems_api; typedef struct { - uint32_t active_condition_variables; uint32_t active_message_queues; uint32_t active_mutexes; uint32_t active_semaphores; diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c index 243ffd33cd..695c94867e 100644 --- a/cpukit/libcsupport/src/resource_snapshot.c +++ b/cpukit/libcsupport/src/resource_snapshot.c @@ -42,7 +42,6 @@ #ifdef RTEMS_POSIX_API #include - #include #include #include #include @@ -68,7 +67,6 @@ static const struct { { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS } #ifdef RTEMS_POSIX_API , - { OBJECTS_POSIX_API, OBJECTS_POSIX_CONDITION_VARIABLES }, { OBJECTS_POSIX_API, OBJECTS_POSIX_MESSAGE_QUEUES }, { OBJECTS_POSIX_API, OBJECTS_POSIX_MUTEXES }, { OBJECTS_POSIX_API, OBJECTS_POSIX_SEMAPHORES }, 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 -#include - -#include - -#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 -#include -#include #include +#include + +#include +#include #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 @@ -68,12 +68,6 @@ typedef struct { */ uint32_t maximum_mutexes; - /** - * 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. 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 -#include -#include - -#include -#include -#include -#include -#include -#include - -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 -#include - -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 #include +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 +#include + +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 #include -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 diff --git a/cpukit/rtems/src/rtemsobjectgetapiclassname.c b/cpukit/rtems/src/rtemsobjectgetapiclassname.c index b2db41a8df..00f0de894a 100644 --- a/cpukit/rtems/src/rtemsobjectgetapiclassname.c +++ b/cpukit/rtems/src/rtemsobjectgetapiclassname.c @@ -51,7 +51,6 @@ static const rtems_assoc_t rtems_object_api_posix_assoc[] = { { "Message Queue", OBJECTS_POSIX_MESSAGE_QUEUES, 0}, { "Mutex", OBJECTS_POSIX_MUTEXES, 0}, { "Semaphore", OBJECTS_POSIX_SEMAPHORES, 0}, - { "Condition Variable", OBJECTS_POSIX_CONDITION_VARIABLES, 0}, { "Timer", OBJECTS_POSIX_TIMERS, 0}, { "Shared Memory", OBJECTS_POSIX_SHMS, 0}, { NULL, 0, 0} diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h index 596c3420b0..402a467762 100755 --- a/cpukit/sapi/include/confdefs.h +++ b/cpukit/sapi/include/confdefs.h @@ -1841,14 +1841,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; * o bdbuf sync lock */ #define _CONFIGURE_LIBBLOCK_POSIX_MUTEXES 2 - - /* - * POSIX Condition Variables: - * o bdbuf access condition - * o bdbuf transfer condition - * o bdbuf buffer condition - */ - #define _CONFIGURE_LIBBLOCK_POSIX_CONDITION_VARIABLES 3 #else /* * Semaphores: @@ -1862,7 +1854,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #define _CONFIGURE_LIBBLOCK_SEMAPHORES 6 #define _CONFIGURE_LIBBLOCK_POSIX_MUTEXES 0 - #define _CONFIGURE_LIBBLOCK_POSIX_CONDITION_VARIABLES 0 #endif #if defined(CONFIGURE_HAS_OWN_BDBUF_TABLE) || \ @@ -1879,11 +1870,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #define _CONFIGURE_LIBBLOCK_SEMAPHORES 0 /** This specifies the number of POSIX Mutexes needed by libblock. */ #define _CONFIGURE_LIBBLOCK_POSIX_MUTEXES 0 - /** - * This specifies the number of POSIX Condition Variables needed - * by libblock. - */ - #define _CONFIGURE_LIBBLOCK_POSIX_CONDITION_VARIABLES 0 #endif /* CONFIGURE_APPLICATION_NEEDS_LIBBLOCK */ /**@}*/ @@ -2059,10 +2045,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #define CONFIGURE_MAXIMUM_POSIX_MUTEXES \ rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE) #endif - #if !defined(CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES) - #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES \ - rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE) - #endif #if !defined(CONFIGURE_MAXIMUM_POSIX_TIMERS) #define CONFIGURE_MAXIMUM_POSIX_TIMERS \ rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE) @@ -2440,7 +2422,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #include #include #include - #include #include #include #include @@ -2482,22 +2463,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #define _CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_mutexes) \ _Configure_Object_RAM(_mutexes, sizeof(POSIX_Mutex_Control) ) - /** - * This configuration parameter specifies the maximum number of - * POSIX API condition variables. - */ - #ifndef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES - #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 0 - #endif - - /* - * This macro is calculated to specify the memory required for - * POSIX API condition variables. - */ - #define _CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(_condvars) \ - _Configure_Object_RAM(_condvars, \ - sizeof(POSIX_Condition_variables_Control) ) - /** * This configuration parameter specifies the maximum number of * POSIX API timers. @@ -2712,12 +2677,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #ifndef CONFIGURE_MAXIMUM_POSIX_MUTEXES #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1 #endif - #ifndef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES - #define CONFIGURE_MAXIMUM_CONDITION_VARIABLES 1 - #endif #define _CONFIGURE_GO_INIT_MUTEXES 77 - #define _CONFIGURE_GO_INIT_CONDITION_VARIABLES 4 #ifndef CONFIGURE_MAXIMUM_GOROUTINES #define CONFIGURE_MAXIMUM_GOROUTINES 400 @@ -2734,12 +2695,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; */ #define _CONFIGURE_GO_INIT_MUTEXES 0 - /* - * This specifies the number of condition variables required by the Go - * run-time for its own use. - */ - #define _CONFIGURE_GO_INIT_CONDITION_VARIABLES 0 - /** This specifies the maximum number of Go co-routines. */ #define CONFIGURE_MAXIMUM_GOROUTINES 0 @@ -2777,25 +2732,12 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; _CONFIGURE_GO_INIT_MUTEXES + \ CONFIGURE_MAXIMUM_GO_CHANNELS) - /* - * This macro provides summation of the POSIX Condition Variables. - */ - #define _CONFIGURE_POSIX_CONDITION_VARIABLES \ - (CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES + \ - _CONFIGURE_LIBBLOCK_POSIX_CONDITION_VARIABLES + \ - CONFIGURE_MAXIMUM_ADA_TASKS + \ - CONFIGURE_MAXIMUM_FAKE_ADA_TASKS + \ - _CONFIGURE_GO_INIT_CONDITION_VARIABLES + \ - CONFIGURE_MAXIMUM_GO_CHANNELS) - /* * This macro is calculated to specify the memory required for * the POSIX API in its entirety. */ #define _CONFIGURE_MEMORY_FOR_POSIX \ (_CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_CONFIGURE_POSIX_MUTEXES) + \ - _CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( \ - _CONFIGURE_POSIX_CONDITION_VARIABLES) + \ _CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS( \ CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS) + \ _CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES( \ @@ -3248,7 +3190,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; posix_api_configuration_table Configuration_POSIX_API = { _CONFIGURE_POSIX_THREADS, _CONFIGURE_POSIX_MUTEXES, - _CONFIGURE_POSIX_CONDITION_VARIABLES, CONFIGURE_MAXIMUM_POSIX_TIMERS, CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS, CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES, @@ -3462,7 +3403,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #ifdef RTEMS_POSIX_API /* POSIX API Pieces */ uint32_t POSIX_MUTEXES; - uint32_t POSIX_CONDITION_VARIABLES; uint32_t POSIX_TIMERS; uint32_t POSIX_QUEUED_SIGNALS; uint32_t POSIX_MESSAGE_QUEUES; @@ -3512,8 +3452,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #ifdef RTEMS_POSIX_API /* POSIX API Pieces */ _CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( _CONFIGURE_POSIX_MUTEXES ), - _CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( - _CONFIGURE_POSIX_CONDITION_VARIABLES ), _CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS( CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS ), _CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES( @@ -3584,7 +3522,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #if !defined(RTEMS_POSIX_API) #if ((CONFIGURE_MAXIMUM_POSIX_THREADS != 0) || \ (CONFIGURE_MAXIMUM_POSIX_MUTEXES != 0) || \ - (CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES != 0) || \ (CONFIGURE_MAXIMUM_POSIX_TIMERS != 0) || \ (CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS != 0) || \ (CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES != 0) || \ diff --git a/cpukit/sapi/src/posixapi.c b/cpukit/sapi/src/posixapi.c index 41325bb07a..86fdf12a38 100644 --- a/cpukit/sapi/src/posixapi.c +++ b/cpukit/sapi/src/posixapi.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -86,6 +87,26 @@ RTEMS_STATIC_ASSERT( POSIX_RWLOCK_MAGIC != HEAP_FREE_PATTERN, POSIX_RWLOCK_MAGIC_4 ); +RTEMS_STATIC_ASSERT( + POSIX_CONDITION_VARIABLES_MAGIC != HEAP_BEGIN_PROTECTOR_0, + POSIX_CONDITION_VARIABLES_MAGIC_0 +); +RTEMS_STATIC_ASSERT( + POSIX_CONDITION_VARIABLES_MAGIC != HEAP_BEGIN_PROTECTOR_1, + POSIX_CONDITION_VARIABLES_MAGIC_1 +); +RTEMS_STATIC_ASSERT( + POSIX_CONDITION_VARIABLES_MAGIC != HEAP_END_PROTECTOR_0, + POSIX_CONDITION_VARIABLES_MAGIC_2 +); +RTEMS_STATIC_ASSERT( + POSIX_CONDITION_VARIABLES_MAGIC != HEAP_END_PROTECTOR_1, + POSIX_CONDITION_VARIABLES_MAGIC_3 +); +RTEMS_STATIC_ASSERT( + POSIX_CONDITION_VARIABLES_MAGIC != HEAP_FREE_PATTERN, + POSIX_CONDITION_VARIABLES_MAGIC_4 +); #endif RTEMS_STATIC_ASSERT( @@ -96,10 +117,22 @@ RTEMS_STATIC_ASSERT( POSIX_SEMAPHORE_MAGIC != POSIX_RWLOCK_MAGIC, POSIX_SEMAPHORE_MAGIC_6 ); +RTEMS_STATIC_ASSERT( + POSIX_SEMAPHORE_MAGIC != POSIX_CONDITION_VARIABLES_MAGIC, + POSIX_SEMAPHORE_MAGIC_7 +); RTEMS_STATIC_ASSERT( POSIX_BARRIER_MAGIC != POSIX_RWLOCK_MAGIC, POSIX_BARRIER_MAGIC_5 ); +RTEMS_STATIC_ASSERT( + POSIX_BARRIER_MAGIC != POSIX_CONDITION_VARIABLES_MAGIC, + POSIX_BARRIER_MAGIC_6 +); +RTEMS_STATIC_ASSERT( + POSIX_RWLOCK_MAGIC != POSIX_CONDITION_VARIABLES_MAGIC, + POSIX_RWLOCK_MAGIC_5 +); void _POSIX_Fatal_error( POSIX_Fatal_domain domain, int eno ) { diff --git a/cpukit/score/include/rtems/score/objectimpl.h b/cpukit/score/include/rtems/score/objectimpl.h index f8e7ddd284..435e82cc45 100644 --- a/cpukit/score/include/rtems/score/objectimpl.h +++ b/cpukit/score/include/rtems/score/objectimpl.h @@ -89,7 +89,6 @@ typedef enum { OBJECTS_POSIX_MESSAGE_QUEUES = 5, OBJECTS_POSIX_MUTEXES = 6, OBJECTS_POSIX_SEMAPHORES = 7, - OBJECTS_POSIX_CONDITION_VARIABLES = 8, OBJECTS_POSIX_TIMERS = 9, OBJECTS_POSIX_SHMS = 12 } Objects_POSIX_API; diff --git a/cpukit/score/include/rtems/sysinit.h b/cpukit/score/include/rtems/sysinit.h index 09b82e6836..595629fd04 100644 --- a/cpukit/score/include/rtems/sysinit.h +++ b/cpukit/score/include/rtems/sysinit.h @@ -47,7 +47,6 @@ extern "C" { #define RTEMS_SYSINIT_CLASSIC_BARRIER 00034a #define RTEMS_SYSINIT_POSIX_SIGNALS 000360 #define RTEMS_SYSINIT_POSIX_THREADS 000361 -#define RTEMS_SYSINIT_POSIX_CONDITION_VARIABLE 000362 #define RTEMS_SYSINIT_POSIX_MUTEX 000363 #define RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE 000364 #define RTEMS_SYSINIT_POSIX_SEMAPHORE 000365 -- cgit v1.2.3