[PATCH] posix: Implement self-contained POSIX barriers
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Sep 21 13:29:45 UTC 2017
Update #3114.
---
cpukit/libcsupport/include/rtems/libcsupport.h | 1 -
cpukit/libcsupport/src/resource_snapshot.c | 1 -
cpukit/posix/Makefile.am | 3 +-
cpukit/posix/include/rtems/posix/barrier.h | 64 -------------
cpukit/posix/include/rtems/posix/barrierimpl.h | 87 ++++++++++-------
cpukit/posix/include/rtems/posix/config.h | 6 --
cpukit/posix/preinstall.am | 4 -
cpukit/posix/src/pbarrier.c | 51 ----------
cpukit/posix/src/pbarrierdestroy.c | 44 +++------
cpukit/posix/src/pbarrierinit.c | 109 +++++++++-------------
cpukit/posix/src/pbarrierwait.c | 58 +++++++-----
cpukit/rtems/src/rtemsobjectgetapiclassname.c | 1 -
cpukit/sapi/include/confdefs.h | 25 -----
cpukit/score/include/rtems/score/objectimpl.h | 1 -
cpukit/score/include/rtems/sysinit.h | 1 -
testsuites/psxtests/psxbarrier01/main.c | 2 -
testsuites/psxtests/psxbarrier01/psxbarrier01.scn | 7 +-
testsuites/psxtests/psxbarrier01/test.c | 82 +++++++++++-----
testsuites/psxtests/psxconfig01/init.c | 13 ---
testsuites/psxtmtests/psxtmbarrier01/init.c | 1 -
testsuites/psxtmtests/psxtmbarrier02/init.c | 1 -
testsuites/psxtmtests/psxtmbarrier03/init.c | 1 -
testsuites/psxtmtests/psxtmbarrier04/init.c | 1 -
testsuites/sptests/spsysinit01/init.c | 16 ----
24 files changed, 208 insertions(+), 372 deletions(-)
delete mode 100644 cpukit/posix/include/rtems/posix/barrier.h
delete mode 100644 cpukit/posix/src/pbarrier.c
diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h
index e51b250f13..ace61c5c0d 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_barriers;
uint32_t active_condition_variables;
uint32_t active_message_queues;
uint32_t active_mutexes;
diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c
index 9e026ff222..87d4a0108a 100644
--- a/cpukit/libcsupport/src/resource_snapshot.c
+++ b/cpukit/libcsupport/src/resource_snapshot.c
@@ -69,7 +69,6 @@ static const struct {
{ OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS }
#ifdef RTEMS_POSIX_API
,
- { OBJECTS_POSIX_API, OBJECTS_POSIX_BARRIERS },
{ OBJECTS_POSIX_API, OBJECTS_POSIX_CONDITION_VARIABLES },
{ OBJECTS_POSIX_API, OBJECTS_POSIX_MESSAGE_QUEUES },
{ OBJECTS_POSIX_API, OBJECTS_POSIX_MUTEXES },
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 2c88dbbc19..5f76ecc1d4 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -49,7 +49,6 @@ include_rtems_posix_HEADERS += include/rtems/posix/semaphoreimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/threadsup.h
include_rtems_posix_HEADERS += include/rtems/posix/timer.h
include_rtems_posix_HEADERS += include/rtems/posix/timerimpl.h
-include_rtems_posix_HEADERS += include/rtems/posix/barrier.h
include_rtems_posix_HEADERS += include/rtems/posix/barrierimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/rwlock.h
include_rtems_posix_HEADERS += include/rtems/posix/rwlockimpl.h
@@ -73,7 +72,7 @@ libposix_a_SOURCES += src/pthreadatfork.c
## BARRIER_C_FILES
libposix_a_SOURCES += src/barrierattrdestroy.c src/barrierattrgetpshared.c \
- src/barrierattrinit.c src/barrierattrsetpshared.c src/pbarrier.c \
+ src/barrierattrinit.c src/barrierattrsetpshared.c \
src/pbarrierdestroy.c src/pbarrierinit.c \
src/pbarrierwait.c
diff --git a/cpukit/posix/include/rtems/posix/barrier.h b/cpukit/posix/include/rtems/posix/barrier.h
deleted file mode 100644
index e445586511..0000000000
--- a/cpukit/posix/include/rtems/posix/barrier.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * @file
- *
- * @brief Constants and Structures Associated with the POSIX Barrier Manager
- *
- * This include file contains all the constants and structures associated
- * with the POSIX Barrier Manager.
- *
- * Directives provided are:
- *
- * - create a barrier
- * - delete a barrier
- * - wait for a barrier
- */
-
-/*
- * 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_BARRIER_H
-#define _RTEMS_POSIX_BARRIER_H
-
-#include <rtems/score/object.h>
-#include <rtems/score/corebarrier.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @defgroup POSIXBarrier POSIX Barriers
- *
- * @ingroup POSIXAPI
- *
- * This encapsulates functionality which implements the RTEMS API
- * Barrier Manager.
- *
- */
-/**@{**/
-
-/**
- * This type defines the control block used to manage each barrier.
- */
-
-typedef struct {
- /** This is used to manage a barrier as an object. */
- Objects_Control Object;
- /** This is used to implement the barrier. */
- CORE_barrier_Control Barrier;
-} POSIX_Barrier_Control;
-
-#ifdef __cplusplus
-}
-#endif
-
-/** @} */
-
-#endif
-/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/barrierimpl.h b/cpukit/posix/include/rtems/posix/barrierimpl.h
index fae66a6171..9f0588050d 100644
--- a/cpukit/posix/include/rtems/posix/barrierimpl.h
+++ b/cpukit/posix/include/rtems/posix/barrierimpl.h
@@ -11,6 +11,8 @@
* COPYRIGHT (c) 1989-2011.
* On-Line Applications Research Corporation (OAR).
*
+ * Copyright (c) 2017 embedded brains GmbH
+ *
* 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.
@@ -19,63 +21,76 @@
#ifndef _RTEMS_POSIX_BARRIERIMPL_H
#define _RTEMS_POSIX_BARRIERIMPL_H
-#include <rtems/posix/barrier.h>
-#include <rtems/score/corebarrierimpl.h>
-#include <rtems/score/objectimpl.h>
-
#include <errno.h>
#include <pthread.h>
+#include <rtems/score/percpu.h>
+#include <rtems/score/threadqimpl.h>
+
#ifdef __cplusplus
extern "C" {
#endif
-/**
- * The following defines the information control block used to manage
- * this class of objects.
- */
+#define POSIX_BARRIER_MAGIC 0x1cf03773UL
-extern Objects_Information _POSIX_Barrier_Information;
+#define POSIX_BARRIER_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
-/**
- * @brief Allocate a barrier control block.
- *
- * This function allocates a barrier control block from
- * the inactive chain of free barrier control blocks.
- */
-RTEMS_INLINE_ROUTINE POSIX_Barrier_Control *_POSIX_Barrier_Allocate( void )
+typedef struct {
+ unsigned long flags;
+ unsigned int count;
+ unsigned int waiting_threads;
+ Thread_queue_Syslock_queue Queue;
+} POSIX_Barrier_Control;
+
+static inline POSIX_Barrier_Control *_POSIX_Barrier_Get(
+ pthread_barrier_t *_barrier
+)
{
- return (POSIX_Barrier_Control *)
- _Objects_Allocate( &_POSIX_Barrier_Information );
+ return (POSIX_Barrier_Control *) _barrier;
}
-/**
- * @brief Free a barrier control block.
- *
- * This routine frees a barrier control block to the
- * inactive chain of free barrier control blocks.
- */
-RTEMS_INLINE_ROUTINE void _POSIX_Barrier_Free (
- POSIX_Barrier_Control *the_barrier
+static inline Thread_Control *_POSIX_Barrier_Queue_acquire(
+ POSIX_Barrier_Control *barrier,
+ Thread_queue_Context *queue_context
)
{
- _CORE_barrier_Destroy( &the_barrier->Barrier );
- _Objects_Free( &_POSIX_Barrier_Information, &the_barrier->Object );
+ ISR_Level level;
+ Thread_Control *executing;
+
+ _Thread_queue_Context_initialize( queue_context );
+ _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(
+ &barrier->Queue.Queue,
+ &executing->Potpourri_stats,
+ &queue_context->Lock_context.Lock_context
+ );
+
+ return executing;
}
-RTEMS_INLINE_ROUTINE POSIX_Barrier_Control *_POSIX_Barrier_Get(
- const pthread_barrier_t *barrier,
- Thread_queue_Context *queue_context
+static inline void _POSIX_Barrier_Queue_release(
+ POSIX_Barrier_Control *barrier,
+ Thread_queue_Context *queue_context
)
{
- _Thread_queue_Context_initialize( queue_context );
- return (POSIX_Barrier_Control *) _Objects_Get(
- (Objects_Id) *barrier,
- &queue_context->Lock_context.Lock_context,
- &_POSIX_Barrier_Information
+ _Thread_queue_Queue_release(
+ &barrier->Queue.Queue,
+ &queue_context->Lock_context.Lock_context
);
}
+#define POSIX_BARRIER_VALIDATE_OBJECT( bar ) \
+ do { \
+ if ( \
+ ( bar ) == NULL \
+ || ( (uintptr_t) ( bar ) ^ POSIX_BARRIER_MAGIC ) != ( bar )->_flags \
+ ) { \
+ 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 6c74216dc2..dc1ef0c2f1 100644
--- a/cpukit/posix/include/rtems/posix/config.h
+++ b/cpukit/posix/include/rtems/posix/config.h
@@ -100,12 +100,6 @@ typedef struct {
/**
* This field contains the maximum number of POSIX API
- * barriers which are configured for this application.
- */
- uint32_t maximum_barriers;
-
- /**
- * This field contains the maximum number of POSIX API
* read/write locks which are configured for this application.
*/
uint32_t maximum_rwlocks;
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
index cfb087c923..c7f071f5fd 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -140,10 +140,6 @@ $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h: include/rtems/posix/timerimpl.h $(PR
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
-$(PROJECT_INCLUDE)/rtems/posix/barrier.h: include/rtems/posix/barrier.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
- $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/barrier.h
-PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/barrier.h
-
$(PROJECT_INCLUDE)/rtems/posix/barrierimpl.h: include/rtems/posix/barrierimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/barrierimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/barrierimpl.h
diff --git a/cpukit/posix/src/pbarrier.c b/cpukit/posix/src/pbarrier.c
deleted file mode 100644
index 8216a080b1..0000000000
--- a/cpukit/posix/src/pbarrier.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * @file
- *
- * This file initializes the POSIX Barrier Manager.
- */
-
-/*
- * COPYRIGHT (c) 1989-2013.
- * 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 <limits.h>
-
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/sysinit.h>
-#include <rtems/posix/barrierimpl.h>
-
-Objects_Information _POSIX_Barrier_Information;
-
-/**
- * @brief _POSIX_Barrier_Manager_initialization
- */
-static void _POSIX_Barrier_Manager_initialization(void)
-{
- _Objects_Initialize_information(
- &_POSIX_Barrier_Information, /* object information table */
- OBJECTS_POSIX_API, /* object API */
- OBJECTS_POSIX_BARRIERS, /* object class */
- Configuration_POSIX_API.maximum_barriers,
- /* maximum objects of this class */
- sizeof( POSIX_Barrier_Control ),/* size of this object's control block */
- true, /* true if the name is a string */
- _POSIX_PATH_MAX, /* maximum length of each object's name */
- NULL /* Proxy extraction support callout */
- );
-}
-
-RTEMS_SYSINIT_ITEM(
- _POSIX_Barrier_Manager_initialization,
- RTEMS_SYSINIT_POSIX_BARRIER,
- RTEMS_SYSINIT_ORDER_MIDDLE
-);
diff --git a/cpukit/posix/src/pbarrierdestroy.c b/cpukit/posix/src/pbarrierdestroy.c
index 8f85762211..83d06318b5 100644
--- a/cpukit/posix/src/pbarrierdestroy.c
+++ b/cpukit/posix/src/pbarrierdestroy.c
@@ -9,6 +9,8 @@
* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
+ * Copyright (c) 2017 embedded brains GmbH
+ *
* 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.
@@ -20,47 +22,23 @@
#include <rtems/posix/barrierimpl.h>
-/**
- * This directive allows a thread to delete a barrier specified by
- * the barrier id. The barrier is freed back to the inactive
- * barrier chain.
- *
- * @param[in] barrier is the barrier id
- *
- * @return This method returns 0 if there was not an
- * error. Otherwise, a status code is returned indicating the
- * source of the error.
- */
-int pthread_barrier_destroy(
- pthread_barrier_t *barrier
-)
+int pthread_barrier_destroy( pthread_barrier_t *_barrier )
{
- POSIX_Barrier_Control *the_barrier;
+ POSIX_Barrier_Control *barrier;
Thread_queue_Context queue_context;
- if ( barrier == NULL ) {
- return EINVAL;
- }
-
- _Objects_Allocator_lock();
- the_barrier = _POSIX_Barrier_Get( barrier, &queue_context );
+ POSIX_BARRIER_VALIDATE_OBJECT( _barrier );
- if ( the_barrier == NULL ) {
- _Objects_Allocator_unlock();
- return EINVAL;
- }
+ barrier = _POSIX_Barrier_Get( _barrier );
- _CORE_barrier_Acquire_critical( &the_barrier->Barrier, &queue_context );
+ _POSIX_Barrier_Queue_acquire( barrier, &queue_context );
- if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) {
- _CORE_barrier_Release( &the_barrier->Barrier, &queue_context );
- _Objects_Allocator_unlock();
+ if ( barrier->waiting_threads != 0 ) {
+ _POSIX_Barrier_Queue_release( barrier, &queue_context );
return EBUSY;
}
- _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object );
- _CORE_barrier_Release( &the_barrier->Barrier, &queue_context );
- _POSIX_Barrier_Free( the_barrier );
- _Objects_Allocator_unlock();
+ barrier->flags = 0;
+ _POSIX_Barrier_Queue_release( barrier, &queue_context );
return 0;
}
diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c
index c14cc0cb90..7f434c9dcc 100644
--- a/cpukit/posix/src/pbarrierinit.c
+++ b/cpukit/posix/src/pbarrierinit.c
@@ -11,6 +11,8 @@
* COPYRIGHT (c) 1989-2006.
* On-Line Applications Research Corporation (OAR).
*
+ * Copyright (c) 2017 embedded brains GmbH
+ *
* 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.
@@ -20,28 +22,37 @@
#include "config.h"
#endif
-#include <pthread.h>
-#include <errno.h>
-
-#include <rtems/system.h>
#include <rtems/posix/barrierimpl.h>
#include <rtems/posix/posixapi.h>
-/*
- * pthread_barrier_init
- *
- * This directive creates a barrier. A barrier id is returned.
- *
- * Input parameters:
- * barrier - pointer to barrier id
- * attr - barrier attributes
- * count - number of threads before automatic release
- *
- * Output parameters:
- * barrier - barrier id
- * 0 - if successful
- * error code - if unsuccessful
- */
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_Barrier_Control, flags )
+ == offsetof( pthread_barrier_t, _flags ),
+ POSIX_BARRIER_CONTROL_FLAGS
+);
+
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_Barrier_Control, count )
+ == offsetof( pthread_barrier_t, _count ),
+ POSIX_BARRIER_CONTROL_COUNT
+);
+
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_Barrier_Control, waiting_threads )
+ == offsetof( pthread_barrier_t, _waiting_threads ),
+ POSIX_BARRIER_CONTROL_WAITING_THREADS
+);
+
+RTEMS_STATIC_ASSERT(
+ offsetof( POSIX_Barrier_Control, Queue )
+ == offsetof( pthread_barrier_t, _Queue ),
+ POSIX_BARRIER_CONTROL_QUEUE
+);
+
+RTEMS_STATIC_ASSERT(
+ sizeof( POSIX_Barrier_Control ) == sizeof( pthread_barrier_t ),
+ POSIX_BARRIER_CONTROL_SIZE
+);
int pthread_barrier_init(
pthread_barrier_t *barrier,
@@ -49,62 +60,34 @@ int pthread_barrier_init(
unsigned int count
)
{
- POSIX_Barrier_Control *the_barrier;
- CORE_barrier_Attributes the_attributes;
- pthread_barrierattr_t my_attr;
- const pthread_barrierattr_t *the_attr;
+ struct _Thread_queue_Queue queue = _THREAD_QUEUE_INITIALIZER;
/*
* Error check parameters
*/
- if ( !barrier )
- return EINVAL;
-
- if ( count == 0 )
+ if ( barrier == NULL ) {
return EINVAL;
-
- /*
- * If the user passed in NULL, use the default attributes
- */
- if ( attr ) {
- the_attr = attr;
- } else {
- (void) pthread_barrierattr_init( &my_attr );
- the_attr = &my_attr;
}
- /*
- * Now start error checking the attributes that we are going to use
- */
- if ( !the_attr->is_initialized )
- return EINVAL;
-
- if ( !_POSIX_Is_valid_pshared( the_attr->process_shared ) ) {
+ if ( count == 0 ) {
return EINVAL;
}
- /*
- * Convert from POSIX attributes to Core Barrier attributes
- */
- the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
- the_attributes.maximum_count = count;
-
- the_barrier = _POSIX_Barrier_Allocate();
+ if ( attr != NULL ) {
+ /*
+ * Now start error checking the attributes that we are going to use
+ */
+ if ( !attr->is_initialized )
+ return EINVAL;
- if ( !the_barrier ) {
- _Objects_Allocator_unlock();
- return EAGAIN;
+ if ( !_POSIX_Is_valid_pshared( attr->process_shared ) ) {
+ return EINVAL;
+ }
}
- _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
-
- _Objects_Open_u32(
- &_POSIX_Barrier_Information,
- &the_barrier->Object,
- 0
- );
-
- *barrier = the_barrier->Object.id;
- _Objects_Allocator_unlock();
+ barrier->_flags = (uintptr_t) barrier ^ POSIX_BARRIER_MAGIC;
+ barrier->_count = count;
+ barrier->_waiting_threads = 0;
+ barrier->_Queue = queue;
return 0;
}
diff --git a/cpukit/posix/src/pbarrierwait.c b/cpukit/posix/src/pbarrierwait.c
index 117beac553..9719112256 100644
--- a/cpukit/posix/src/pbarrierwait.c
+++ b/cpukit/posix/src/pbarrierwait.c
@@ -9,6 +9,8 @@
* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
+ * Copyright (c) 2017 embedded brains GmbH
+ *
* 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.
@@ -21,32 +23,44 @@
#include <rtems/posix/barrierimpl.h>
#include <rtems/posix/posixapi.h>
-THREAD_QUEUE_OBJECT_ASSERT( POSIX_Barrier_Control, Barrier.Wait_queue );
-
-int pthread_barrier_wait(
- pthread_barrier_t *barrier
-)
+int pthread_barrier_wait( pthread_barrier_t *_barrier )
{
- POSIX_Barrier_Control *the_barrier;
+ POSIX_Barrier_Control *barrier;
Thread_queue_Context queue_context;
- Status_Control status;
+ Thread_Control *executing;
+ unsigned int waiting_threads;
- if ( barrier == NULL ) {
- return EINVAL;
- }
+ POSIX_BARRIER_VALIDATE_OBJECT( _barrier );
- the_barrier = _POSIX_Barrier_Get( barrier, &queue_context );
+ barrier = _POSIX_Barrier_Get( _barrier );
- if ( the_barrier == NULL ) {
- return EINVAL;
- }
+ executing = _POSIX_Barrier_Queue_acquire( barrier, &queue_context );
+ waiting_threads = barrier->waiting_threads;
+ ++waiting_threads;
- _Thread_queue_Context_set_no_timeout( &queue_context );
- status = _CORE_barrier_Seize(
- &the_barrier->Barrier,
- _Thread_Executing,
- true,
- &queue_context
- );
- return _POSIX_Get_error( status );
+ if ( waiting_threads == barrier->count ) {
+ barrier->waiting_threads = 0;
+ _Thread_queue_Flush_critical(
+ &barrier->Queue.Queue,
+ POSIX_BARRIER_TQ_OPERATIONS,
+ _Thread_queue_Flush_default_filter,
+ &queue_context
+ );
+ return PTHREAD_BARRIER_SERIAL_THREAD;
+ } else {
+ barrier->waiting_threads = waiting_threads;
+ _Thread_queue_Context_set_thread_state(
+ &queue_context,
+ STATES_WAITING_FOR_BARRIER
+ );
+ _Thread_queue_Context_set_do_nothing_enqueue_callout( &queue_context );
+ _Thread_queue_Context_set_no_timeout( &queue_context );
+ _Thread_queue_Enqueue(
+ &barrier->Queue.Queue,
+ POSIX_BARRIER_TQ_OPERATIONS,
+ executing,
+ &queue_context
+ );
+ return 0;
+ }
}
diff --git a/cpukit/rtems/src/rtemsobjectgetapiclassname.c b/cpukit/rtems/src/rtemsobjectgetapiclassname.c
index 4d3b1cb37c..ecac3a5c5f 100644
--- a/cpukit/rtems/src/rtemsobjectgetapiclassname.c
+++ b/cpukit/rtems/src/rtemsobjectgetapiclassname.c
@@ -53,7 +53,6 @@ static const rtems_assoc_t rtems_object_api_posix_assoc[] = {
{ "Semaphore", OBJECTS_POSIX_SEMAPHORES, 0},
{ "Condition Variable", OBJECTS_POSIX_CONDITION_VARIABLES, 0},
{ "Timer", OBJECTS_POSIX_TIMERS, 0},
- { "Barrier", OBJECTS_POSIX_BARRIERS, 0},
{ "RWLock", OBJECTS_POSIX_RWLOCKS, 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 5fe366089e..c8bb18ae07 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -2081,10 +2081,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES \
rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
#endif
- #if !defined(CONFIGURE_MAXIMUM_POSIX_BARRIERS)
- #define CONFIGURE_MAXIMUM_POSIX_BARRIERS \
- rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
- #endif
#if !defined(CONFIGURE_MAXIMUM_POSIX_RWLOCKS)
#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS \
rtems_resource_unlimited(CONFIGURE_UNLIMITED_ALLOCATION_SIZE)
@@ -2448,7 +2444,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
#include <signal.h>
#include <limits.h>
#include <mqueue.h>
- #include <rtems/posix/barrier.h>
#include <rtems/posix/cond.h>
#include <rtems/posix/mqueue.h>
#include <rtems/posix/mutex.h>
@@ -2573,21 +2568,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
/**
* This configuration parameter specifies the maximum number of
- * POSIX API barriers.
- */
- #ifndef CONFIGURE_MAXIMUM_POSIX_BARRIERS
- #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 0
- #endif
-
- /*
- * This macro is calculated to specify the memory required for
- * POSIX API barriers.
- */
- #define _CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(_barriers) \
- _Configure_Object_RAM(_barriers, sizeof(POSIX_Barrier_Control) )
-
- /**
- * This configuration parameter specifies the maximum number of
* POSIX API rwlocks.
*/
#ifndef CONFIGURE_MAXIMUM_POSIX_RWLOCKS
@@ -2842,7 +2822,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES) + \
_CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( \
CONFIGURE_MAXIMUM_POSIX_SEMAPHORES) + \
- _CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(CONFIGURE_MAXIMUM_POSIX_BARRIERS) + \
_CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( \
CONFIGURE_MAXIMUM_POSIX_RWLOCKS) + \
_CONFIGURE_MEMORY_FOR_POSIX_SHMS( \
@@ -3296,7 +3275,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS,
CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES,
CONFIGURE_MAXIMUM_POSIX_SEMAPHORES,
- CONFIGURE_MAXIMUM_POSIX_BARRIERS,
CONFIGURE_MAXIMUM_POSIX_RWLOCKS,
CONFIGURE_MAXIMUM_POSIX_SHMS,
CONFIGURE_POSIX_INIT_THREAD_TABLE_SIZE,
@@ -3512,7 +3490,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
uint32_t POSIX_QUEUED_SIGNALS;
uint32_t POSIX_MESSAGE_QUEUES;
uint32_t POSIX_SEMAPHORES;
- uint32_t POSIX_BARRIERS;
uint32_t POSIX_RWLOCKS;
uint32_t POSIX_SHMS;
#endif
@@ -3566,7 +3543,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
_CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(
CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES ),
_CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( CONFIGURE_MAXIMUM_POSIX_SEMAPHORES ),
- _CONFIGURE_MEMORY_FOR_POSIX_BARRIERS( CONFIGURE_MAXIMUM_POSIX_BARRIERS ),
_CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS( CONFIGURE_MAXIMUM_POSIX_RWLOCKS ),
_CONFIGURE_MEMORY_FOR_POSIX_SHMS( CONFIGURE_MAXIMUM_POSIX_SHMS ),
_CONFIGURE_MEMORY_FOR_POSIX_TIMERS( CONFIGURE_MAXIMUM_POSIX_TIMERS ),
@@ -3638,7 +3614,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
(CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS != 0) || \
(CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES != 0) || \
(CONFIGURE_MAXIMUM_POSIX_SEMAPHORES != 0) || \
- (CONFIGURE_MAXIMUM_POSIX_BARRIERS != 0) || \
(CONFIGURE_MAXIMUM_POSIX_RWLOCKS != 0) || \
(CONFIGURE_MAXIMUM_POSIX_SHMS != 0) || \
defined(CONFIGURE_POSIX_INIT_THREAD_TABLE))
diff --git a/cpukit/score/include/rtems/score/objectimpl.h b/cpukit/score/include/rtems/score/objectimpl.h
index cd36ce6316..e68035d338 100644
--- a/cpukit/score/include/rtems/score/objectimpl.h
+++ b/cpukit/score/include/rtems/score/objectimpl.h
@@ -91,7 +91,6 @@ typedef enum {
OBJECTS_POSIX_SEMAPHORES = 7,
OBJECTS_POSIX_CONDITION_VARIABLES = 8,
OBJECTS_POSIX_TIMERS = 9,
- OBJECTS_POSIX_BARRIERS = 10,
OBJECTS_POSIX_RWLOCKS = 11,
OBJECTS_POSIX_SHMS = 12
} Objects_POSIX_API;
diff --git a/cpukit/score/include/rtems/sysinit.h b/cpukit/score/include/rtems/sysinit.h
index bd4778ab5c..29ad24dc2f 100644
--- a/cpukit/score/include/rtems/sysinit.h
+++ b/cpukit/score/include/rtems/sysinit.h
@@ -52,7 +52,6 @@ extern "C" {
#define RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE 000364
#define RTEMS_SYSINIT_POSIX_SEMAPHORE 000365
#define RTEMS_SYSINIT_POSIX_TIMER 000366
-#define RTEMS_SYSINIT_POSIX_BARRIER 000367
#define RTEMS_SYSINIT_POSIX_RWLOCK 000368
#define RTEMS_SYSINIT_POSIX_SHM 000369
#define RTEMS_SYSINIT_POSIX_KEYS 00036a
diff --git a/testsuites/psxtests/psxbarrier01/main.c b/testsuites/psxtests/psxbarrier01/main.c
index 6475016730..f031c05b3c 100644
--- a/testsuites/psxtests/psxbarrier01/main.c
+++ b/testsuites/psxtests/psxbarrier01/main.c
@@ -40,8 +40,6 @@ rtems_task Init(
#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1
-
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/psxtests/psxbarrier01/psxbarrier01.scn b/testsuites/psxtests/psxbarrier01/psxbarrier01.scn
index d568d8d03e..c7ef3fd245 100644
--- a/testsuites/psxtests/psxbarrier01/psxbarrier01.scn
+++ b/testsuites/psxtests/psxbarrier01/psxbarrier01.scn
@@ -23,14 +23,11 @@ pthread_barrier_init( &barrier, &attr, 1 ) -- EINVAL
pthread_barrierattr_setpshared( &attr, shared ) -- OK
pthread_barrier_init( &barrier, &attr, 1 ) -- OK
pthread_barrier_destroy( &barrier ) -- OK
-pthread_barrier_init( &barrier, NULL, 1 ) -- OK
-pthread_barrier_init( &barrier, NULL, 1 ) -- EAGAIN
-pthread_barrier_destroy( &barrier ) -- OK
pthread_barrierattr_destroy( &attr ) -- OK
pthread_barrier_destroy( NULL ) -- EINVAL
-pthread_barrier_destroy( &bad_barrier ) -- EINVAL
+pthread_barrier_destroy( bad_barrier ) -- EINVAL
pthread_barrier_wait( NULL ) -- EINVAL
-pthread_barrier_wait( &bad_barrier ) -- EINVAL
+pthread_barrier_wait( bad_barrier ) -- EINVAL
pthread_barrierattr_init( &attr ) -- OK
pthread_barrier_init( &barrier, &attr, 2 ) -- OK
pthread_barrier_destroy( &barrier ) -- OK
diff --git a/testsuites/psxtests/psxbarrier01/test.c b/testsuites/psxtests/psxbarrier01/test.c
index 16e8665b94..4253b21057 100644
--- a/testsuites/psxtests/psxbarrier01/test.c
+++ b/testsuites/psxtests/psxbarrier01/test.c
@@ -4,6 +4,8 @@
* COPYRIGHT (c) 1989-2009.
* On-Line Applications Research Corporation (OAR).
*
+ * Copyright (c) 2017 embedded brains GmbH
+ *
* 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.
@@ -16,6 +18,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
/* #define __USE_XOPEN2K XXX already defined on GNU/Linux */
#include <pthread.h>
@@ -24,6 +27,55 @@
const char rtems_test_name[] = "PSXBARRIER 1";
+static void test_barrier_null( void )
+{
+ int eno;
+
+ eno = pthread_barrier_init( NULL, NULL, 1 );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_barrier_wait( NULL );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_barrier_destroy( NULL );
+ rtems_test_assert( eno == EINVAL );
+}
+
+static void test_barrier_not_initialized( void )
+{
+ pthread_barrier_t bar;
+ int eno;
+
+ memset( &bar, 0xff, sizeof( bar ) );
+
+ eno = pthread_barrier_wait(& bar) ;
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_barrier_destroy( &bar );
+ rtems_test_assert( eno == EINVAL );
+}
+
+static void test_barrier_invalid_copy( void )
+{
+ pthread_barrier_t bar;
+ pthread_barrier_t bar2;
+ int eno;
+
+ eno = pthread_barrier_init( &bar, NULL, 1 );
+ rtems_test_assert( eno == 0 );
+
+ memcpy( &bar2, &bar, sizeof( bar2 ) );
+
+ eno = pthread_barrier_wait( &bar2 );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_barrier_destroy( &bar2 );
+ rtems_test_assert( eno == EINVAL );
+
+ eno = pthread_barrier_destroy( &bar );
+ rtems_test_assert( eno == 0 );
+}
+
#define NUMBER_THREADS 2
pthread_t ThreadIds[NUMBER_THREADS];
pthread_barrier_t Barrier;
@@ -57,7 +109,7 @@ int main(
)
#endif
{
- pthread_barrier_t bad_barrier = 100;
+ pthread_barrier_t *bad_barrier = NULL;
pthread_barrier_t barrier;
pthread_barrierattr_t attr;
int status;
@@ -178,20 +230,6 @@ int main(
status = pthread_barrier_destroy( &barrier );
rtems_test_assert( status == 0 );
- /* allocating too many */
- puts( "pthread_barrier_init( &barrier, NULL, 1 ) -- OK" );
- status = pthread_barrier_init( &barrier, NULL, 1 );
- rtems_test_assert( status == 0 );
-
- puts( "pthread_barrier_init( &barrier, NULL, 1 ) -- EAGAIN" );
- status = pthread_barrier_init( &barrier, NULL, 1 );
- rtems_test_assert( status == EAGAIN );
-
- /* clean up */
- puts( "pthread_barrier_destroy( &barrier ) -- OK" );
- status = pthread_barrier_destroy( &barrier );
- rtems_test_assert( status == 0 );
-
puts( "pthread_barrierattr_destroy( &attr ) -- OK" );
status = pthread_barrierattr_destroy( &attr );
rtems_test_assert( status == 0 );
@@ -202,8 +240,8 @@ int main(
status = pthread_barrier_destroy( NULL );
rtems_test_assert( status == EINVAL );
- puts( "pthread_barrier_destroy( &bad_barrier ) -- EINVAL" );
- status = pthread_barrier_destroy( &bad_barrier );
+ puts( "pthread_barrier_destroy( bad_barrier ) -- EINVAL" );
+ status = pthread_barrier_destroy( bad_barrier );
rtems_test_assert( status == EINVAL );
/*************** pthread_barrier_wait ERROR CHECKs *********/
@@ -212,8 +250,8 @@ int main(
status = pthread_barrier_wait( NULL );
rtems_test_assert( status == EINVAL );
- puts( "pthread_barrier_wait( &bad_barrier ) -- EINVAL" );
- status = pthread_barrier_wait( &bad_barrier );
+ puts( "pthread_barrier_wait( bad_barrier ) -- EINVAL" );
+ status = pthread_barrier_wait( bad_barrier );
rtems_test_assert( status == EINVAL );
/*************** ACTUALLY CREATE ONE CHECK *****************/
@@ -224,7 +262,6 @@ int main(
puts( "pthread_barrier_init( &barrier, &attr, 2 ) -- OK" );
status = pthread_barrier_init( &barrier, &attr, 2 );
rtems_test_assert( status == 0 );
- rtems_test_assert( barrier != 0 );
puts( "pthread_barrier_destroy( &barrier ) -- OK" );
status = pthread_barrier_destroy( &barrier );
@@ -234,7 +271,6 @@ int main(
puts( "pthread_barrier_init( &Barrier, &attr, NUMBER_THREADS ) -- OK" );
status = pthread_barrier_init( &Barrier, &attr, NUMBER_THREADS );
rtems_test_assert( status == 0 );
- rtems_test_assert( barrier != 0 );
for (i=0 ; i<NUMBER_THREADS ; i++ ) {
@@ -253,6 +289,10 @@ int main(
sleep(1);
}
+ test_barrier_null();
+ test_barrier_not_initialized();
+ test_barrier_invalid_copy();
+
/*************** END OF TEST *****************/
TEST_END();
exit(0);
diff --git a/testsuites/psxtests/psxconfig01/init.c b/testsuites/psxtests/psxconfig01/init.c
index dd741c11cb..c9e6bfd9fb 100644
--- a/testsuites/psxtests/psxconfig01/init.c
+++ b/testsuites/psxtests/psxconfig01/init.c
@@ -60,7 +60,6 @@ const char rtems_test_name[] = "PSXCONFIG 1";
#define CONFIGURE_MAXIMUM_TIMERS 59
#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 17
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 31
#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 29
#define POSIX_MQ_COUNT 5
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 19
@@ -431,18 +430,6 @@ static rtems_task Init(rtems_task_argument argument)
);
#endif
-#ifdef CONFIGURE_MAXIMUM_POSIX_BARRIERS
- for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_BARRIERS; ++i) {
- pthread_barrier_t barrier;
- eno = pthread_barrier_init(&barrier, NULL, 1);
- rtems_test_assert(eno == 0);
- }
- rtems_resource_snapshot_take(&snapshot);
- rtems_test_assert(
- snapshot.posix_api.active_barriers == CONFIGURE_MAXIMUM_POSIX_BARRIERS
- );
-#endif
-
#ifdef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES
for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES; ++i) {
pthread_cond_t cond;
diff --git a/testsuites/psxtmtests/psxtmbarrier01/init.c b/testsuites/psxtmtests/psxtmbarrier01/init.c
index 690653fe64..7caa6727d0 100644
--- a/testsuites/psxtmtests/psxtmbarrier01/init.c
+++ b/testsuites/psxtmtests/psxtmbarrier01/init.c
@@ -91,7 +91,6 @@ void *POSIX_Init(
#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
#define CONFIGURE_MAXIMUM_POSIX_THREADS 1
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
diff --git a/testsuites/psxtmtests/psxtmbarrier02/init.c b/testsuites/psxtmtests/psxtmbarrier02/init.c
index 0506db9874..6705125ac6 100644
--- a/testsuites/psxtmtests/psxtmbarrier02/init.c
+++ b/testsuites/psxtmtests/psxtmbarrier02/init.c
@@ -133,7 +133,6 @@ void *POSIX_Init(
#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
#define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
diff --git a/testsuites/psxtmtests/psxtmbarrier03/init.c b/testsuites/psxtmtests/psxtmbarrier03/init.c
index d81be082be..27feac1fe8 100644
--- a/testsuites/psxtmtests/psxtmbarrier03/init.c
+++ b/testsuites/psxtmtests/psxtmbarrier03/init.c
@@ -98,7 +98,6 @@ void *POSIX_Init(
#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
diff --git a/testsuites/psxtmtests/psxtmbarrier04/init.c b/testsuites/psxtmtests/psxtmbarrier04/init.c
index 2fc3b76fac..baf1bf1032 100644
--- a/testsuites/psxtmtests/psxtmbarrier04/init.c
+++ b/testsuites/psxtmtests/psxtmbarrier04/init.c
@@ -90,7 +90,6 @@ void *POSIX_Init(
#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
diff --git a/testsuites/sptests/spsysinit01/init.c b/testsuites/sptests/spsysinit01/init.c
index 612ba145a2..ff450b9ace 100644
--- a/testsuites/sptests/spsysinit01/init.c
+++ b/testsuites/sptests/spsysinit01/init.c
@@ -114,8 +114,6 @@ typedef enum {
POSIX_SEMAPHORE_POST,
POSIX_TIMER_PRE,
POSIX_TIMER_POST,
- POSIX_BARRIER_PRE,
- POSIX_BARRIER_POST,
POSIX_RWLOCK_PRE,
POSIX_RWLOCK_POST,
POSIX_SHM_PRE,
@@ -505,18 +503,6 @@ LAST(RTEMS_SYSINIT_POSIX_TIMER)
next_step(POSIX_TIMER_POST);
}
-FIRST(RTEMS_SYSINIT_POSIX_BARRIER)
-{
- assert(_POSIX_Barrier_Information.maximum == 0);
- next_step(POSIX_BARRIER_PRE);
-}
-
-LAST(RTEMS_SYSINIT_POSIX_BARRIER)
-{
- assert(_POSIX_Barrier_Information.maximum != 0);
- next_step(POSIX_BARRIER_POST);
-}
-
FIRST(RTEMS_SYSINIT_POSIX_RWLOCK)
{
assert(_POSIX_RWLock_Information.maximum == 0);
@@ -757,8 +743,6 @@ static void *POSIX_Init(void *arg)
#ifdef RTEMS_POSIX_API
-#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 1
-
#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1
--
2.12.3
More information about the devel
mailing list