summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
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
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')
-rw-r--r--cpukit/posix/Makefile.am11
-rw-r--r--cpukit/posix/include/rtems/posix/barrier.h64
-rw-r--r--cpukit/posix/include/rtems/posix/barrierimpl.h87
-rw-r--r--cpukit/posix/include/rtems/posix/config.h6
-rw-r--r--cpukit/posix/preinstall.am12
-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
9 files changed, 156 insertions, 290 deletions
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 1d9e209101..7980ca3cc5 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -16,6 +16,7 @@ include_rtems_posixdir = $(includedir)/rtems/posix
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/key.h
include_rtems_posix_HEADERS += include/rtems/posix/keyimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/config.h
@@ -49,8 +50,6 @@ include_rtems_posix_HEADERS += include/rtems/posix/shmimpl.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
@@ -68,15 +67,15 @@ libposix_a_SOURCES += src/wait.c src/waitpid.c
libposix_a_SOURCES += src/pthreadgetnamenp.c
libposix_a_SOURCES += src/pthreadsetnamenp.c
-if HAS_PTHREADS
-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
+if HAS_PTHREADS
+libposix_a_SOURCES += src/pthreadatfork.c
+
## CANCEL_C_FILES
libposix_a_SOURCES += src/cancel.c \
src/cleanuppush.c src/setcancelstate.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..a1794b82fd 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;
+ Thread_queue_Syslock_queue Queue;
+ unsigned int count;
+ unsigned int waiting_threads;
+} 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 d67f9face8..903591ad65 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -27,6 +27,10 @@ $(PROJECT_INCLUDE)/rtems/posix/sigset.h: include/rtems/posix/sigset.h $(PROJECT_
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/sigset.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/sigset.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
+
$(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
@@ -140,14 +144,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
-
$(PROJECT_INCLUDE)/rtems/posix/rwlock.h: include/rtems/posix/rwlock.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlock.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlock.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..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;
+ }
}