source: rtems/cpukit/posix/src/pbarrierinit.c @ 77fbbd6

5
Last change on this file since 77fbbd6 was e67929c, checked in by Sebastian Huber <sebastian.huber@…>, on 09/21/17 at 12:13:16

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.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Call to Function Enables Reinitializing of the Barrier
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  POSIX Barrier Manager -- Initialize a Barrier Instance
10 *
11 *  COPYRIGHT (c) 1989-2006.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  Copyright (c) 2017 embedded brains GmbH
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#if HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <rtems/posix/barrierimpl.h>
26#include <rtems/posix/posixapi.h>
27
28RTEMS_STATIC_ASSERT(
29  offsetof( POSIX_Barrier_Control, flags )
30    == offsetof( pthread_barrier_t, _flags ),
31  POSIX_BARRIER_CONTROL_FLAGS
32);
33
34RTEMS_STATIC_ASSERT(
35  offsetof( POSIX_Barrier_Control, count )
36    == offsetof( pthread_barrier_t, _count ),
37  POSIX_BARRIER_CONTROL_COUNT
38);
39
40RTEMS_STATIC_ASSERT(
41  offsetof( POSIX_Barrier_Control, waiting_threads )
42    == offsetof( pthread_barrier_t, _waiting_threads ),
43  POSIX_BARRIER_CONTROL_WAITING_THREADS
44);
45
46RTEMS_STATIC_ASSERT(
47  offsetof( POSIX_Barrier_Control, Queue )
48    == offsetof( pthread_barrier_t, _Queue ),
49  POSIX_BARRIER_CONTROL_QUEUE
50);
51
52RTEMS_STATIC_ASSERT(
53  sizeof( POSIX_Barrier_Control ) == sizeof( pthread_barrier_t ),
54  POSIX_BARRIER_CONTROL_SIZE
55);
56
57int pthread_barrier_init(
58  pthread_barrier_t           *_barrier,
59  const pthread_barrierattr_t *attr,
60  unsigned int                 count
61)
62{
63  POSIX_Barrier_Control *barrier;
64
65  barrier = _POSIX_Barrier_Get( _barrier );
66
67  /*
68   *  Error check parameters
69   */
70  if ( barrier == NULL ) {
71    return EINVAL;
72  }
73
74  if ( count == 0 ) {
75    return EINVAL;
76  }
77
78  if ( attr != NULL ) {
79    /*
80     * Now start error checking the attributes that we are going to use
81     */
82    if ( !attr->is_initialized )
83      return EINVAL;
84
85    if ( !_POSIX_Is_valid_pshared( attr->process_shared ) ) {
86      return EINVAL;
87    }
88  }
89
90  barrier->flags = (uintptr_t) barrier ^ POSIX_BARRIER_MAGIC;
91  barrier->count = count;
92  barrier->waiting_threads = 0;
93  _Thread_queue_Queue_initialize( &barrier->Queue.Queue, NULL );
94  return 0;
95}
Note: See TracBrowser for help on using the repository browser.