summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-09-21 14:13:16 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-05 14:29:01 +0200
commite67929c4c0025ef46053523be4c8736dd178cbec (patch)
tree09fca2c6ff8369031b9e76d97872da12236e155a /cpukit/posix/src
parentposix: Implement self-contained POSIX semaphores (diff)
downloadrtems-e67929c4c0025ef46053523be4c8736dd178cbec.tar.bz2
posix: Implement self-contained POSIX barriers
POSIX barriers are now available in all configurations and no longer depend on --enable-posix. Update #2514. Update #3114.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/pbarrier.c51
-rw-r--r--cpukit/posix/src/pbarrierdestroy.c44
-rw-r--r--cpukit/posix/src/pbarrierinit.c113
-rw-r--r--cpukit/posix/src/pbarrierwait.c58
4 files changed, 96 insertions, 170 deletions
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..1fa22cb024 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,91 +22,74 @@
#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,
+ pthread_barrier_t *_barrier,
const pthread_barrierattr_t *attr,
unsigned int count
)
{
- POSIX_Barrier_Control *the_barrier;
- CORE_barrier_Attributes the_attributes;
- pthread_barrierattr_t my_attr;
- const pthread_barrierattr_t *the_attr;
+ POSIX_Barrier_Control *barrier;
+
+ barrier = _POSIX_Barrier_Get( _barrier );
/*
* Error check parameters
*/
- if ( !barrier )
+ if ( barrier == NULL ) {
return EINVAL;
-
- if ( count == 0 )
- 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;
+ _Thread_queue_Queue_initialize( &barrier->Queue.Queue, NULL );
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;
+ }
}