source: rtems/cpukit/posix/src/pbarrierinit.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.7 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 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <pthread.h>
24#include <errno.h>
25
26#include <rtems/system.h>
27#include <rtems/posix/barrierimpl.h>
28
29/*
30 *  pthread_barrier_init
31 *
32 *  This directive creates a barrier.  A barrier id is returned.
33 *
34 *  Input parameters:
35 *    barrier          - pointer to barrier id
36 *    attr             - barrier attributes
37 *    count            - number of threads before automatic release
38 *
39 *  Output parameters:
40 *    barrier     - barrier id
41 *    0           - if successful
42 *    error code  - if unsuccessful
43 */
44
45int pthread_barrier_init(
46  pthread_barrier_t           *barrier,
47  const pthread_barrierattr_t *attr,
48  unsigned int                 count
49)
50{
51  POSIX_Barrier_Control         *the_barrier;
52  CORE_barrier_Attributes        the_attributes;
53  pthread_barrierattr_t          my_attr;
54  const pthread_barrierattr_t   *the_attr;
55
56  /*
57   *  Error check parameters
58   */
59  if ( !barrier )
60    return EINVAL;
61
62  if ( count == 0 )
63    return EINVAL;
64
65  /*
66   * If the user passed in NULL, use the default attributes
67   */
68  if ( attr ) {
69    the_attr = attr;
70  } else {
71    (void) pthread_barrierattr_init( &my_attr );
72    the_attr = &my_attr;
73  }
74
75  /*
76   * Now start error checking the attributes that we are going to use
77   */
78  if ( !the_attr->is_initialized )
79    return EINVAL;
80
81  switch ( the_attr->process_shared ) {
82    case PTHREAD_PROCESS_PRIVATE:    /* only supported values */
83      break;
84    case PTHREAD_PROCESS_SHARED:
85    default:
86      return EINVAL;
87  }
88
89  /*
90   * Convert from POSIX attributes to Core Barrier attributes
91   */
92  the_attributes.discipline    = CORE_BARRIER_AUTOMATIC_RELEASE;
93  the_attributes.maximum_count = count;
94
95  /*
96   * Enter dispatching critical section to allocate and initialize barrier
97   */
98  _Thread_Disable_dispatch();             /* prevents deletion */
99
100  the_barrier = _POSIX_Barrier_Allocate();
101
102  if ( !the_barrier ) {
103    _Thread_Enable_dispatch();
104    return EAGAIN;
105  }
106
107  _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
108
109  _Objects_Open_u32(
110    &_POSIX_Barrier_Information,
111    &the_barrier->Object,
112    0
113  );
114
115  /*
116   * Exit the critical section and return the user an operational barrier
117   */
118  *barrier = the_barrier->Object.id;
119  _Thread_Enable_dispatch();
120  return 0;
121}
Note: See TracBrowser for help on using the repository browser.