source: rtems/cpukit/posix/src/pbarrierinit.c @ 8a8f5b2

4.104.114.95
Last change on this file since 8a8f5b2 was 8a8f5b2, checked in by Glenn Humphrey <glenn.humphrey@…>, on 11/06/07 at 19:52:36

2007-11-06 Glenn Humphrey <glenn.humphrey@…>

Miscellaneous changes made after a review against the POSIX spec.

  • posix/src/pbarrierinit.c, posix/src/prwlockinit.c: If the caller passes a NULL in the attributes parameter, default attributes are used.
  • posix/src/prwlockdestroy.c: If there is at least one thread waiting, do not allow deletion.
  • posix/src/prwlockwrlock.c: Corrected parameter passed to the core operation used to obtain a RWLock for writing.
  • posix/src/pspinlocktranslatereturncode.c, score/include/rtems/score/corespinlock.h, score/src/corespinlockrelease.c: If the current thread is not the holder of the lock, do not allow an unlock and return EPERM.
  • score/src/corerwlockobtainwrite.c: Corrected to use the operation for queueing with a timeout handler.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  POSIX Barrier Manager -- Initialize a Barrier Instance
3 *
4 *  COPYRIGHT (c) 1989-2006.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <pthread.h>
19#include <errno.h>
20
21#include <rtems/system.h>
22#include <rtems/posix/barrier.h>
23
24/*
25 *  pthread_barrier_init
26 *
27 *  This directive creates a barrier.  A barrier id is returned.
28 *
29 *  Input parameters:
30 *    barrier          - pointer to barrier id
31 *    attr             - barrier attributes
32 *    count            - number of threads before automatic release
33 *
34 *  Output parameters:
35 *    barrier     - barrier id
36 *    0           - if successful
37 *    error code  - if unsuccessful
38 */
39
40int pthread_barrier_init(
41  pthread_barrier_t           *barrier,
42  const pthread_barrierattr_t *attr,
43  unsigned int                 count
44)
45{
46  POSIX_Barrier_Control         *the_barrier;
47  CORE_barrier_Attributes        the_attributes;
48  pthread_barrierattr_t          my_attr;
49  const pthread_barrierattr_t   *the_attr;
50
51  /*
52   *  Error check parameters
53   */
54  if ( !barrier )
55    return EINVAL;
56
57  if ( count == 0 )
58    return EINVAL;
59
60  /*
61   * If the user passed in NULL, use the default attributes
62   */
63  if ( attr ) {
64    the_attr = attr;
65  } else {
66    (void) pthread_barrierattr_init( &my_attr );
67    the_attr = &my_attr;
68  }
69
70  /*
71   * Now start error checking the attributes that we are going to use
72   */
73  if ( !the_attr->is_initialized )
74    return EINVAL;
75
76  switch ( the_attr->process_shared ) {
77    case PTHREAD_PROCESS_PRIVATE:    /* only supported values */
78      break;
79    case PTHREAD_PROCESS_SHARED:
80    default:
81      return EINVAL;
82  }
83
84  /*
85   * Convert from POSIX attributes to Core Barrier attributes
86   */
87  the_attributes.discipline    = CORE_BARRIER_AUTOMATIC_RELEASE;
88  the_attributes.maximum_count = count;
89
90  /*
91   * Enter dispatching critical section to allocate and initialize barrier
92   */
93  _Thread_Disable_dispatch();             /* prevents deletion */
94
95  the_barrier = _POSIX_Barrier_Allocate();
96
97  if ( !the_barrier ) {
98    _Thread_Enable_dispatch();
99    return EAGAIN;
100  }
101
102  _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
103
104  _Objects_Open(
105    &_POSIX_Barrier_Information,
106    &the_barrier->Object,
107    0
108  );
109
110  /*
111   * Exit the critical section and return the user an operational barrier
112   */
113  *barrier = the_barrier->Object.id;
114  _Thread_Enable_dispatch();
115  return 0;
116}
Note: See TracBrowser for help on using the repository browser.