source: rtems/cpukit/rtems/src/barriercreate.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.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Create Barrier
5 * @ingroup ClassicBarrier Barriers
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/rtems/status.h>
23#include <rtems/rtems/support.h>
24#include <rtems/rtems/attrimpl.h>
25#include <rtems/score/isr.h>
26#include <rtems/rtems/barrierimpl.h>
27
28/*
29 *  rtems_barrier_create
30 *
31 *  This directive creates a barrier.  A barrier id is returned.
32 *
33 *  Input parameters:
34 *    name             - user defined barrier name
35 *    attribute_set    - barrier attributes
36 *    maximum_waiters  - number of threads before automatic release
37 *    priority_ceiling - barrier's ceiling priority
38 *    id               - pointer to barrier id
39 *
40 *  Output parameters:
41 *    id               - barrier id
42 *    RTEMS_SUCCESSFUL - if successful
43 *    error code       - if unsuccessful
44 */
45
46rtems_status_code rtems_barrier_create(
47  rtems_name           name,
48  rtems_attribute      attribute_set,
49  uint32_t             maximum_waiters,
50  rtems_id            *id
51)
52{
53  Barrier_Control         *the_barrier;
54  CORE_barrier_Attributes  the_attributes;
55
56  if ( !rtems_is_name_valid( name ) )
57    return RTEMS_INVALID_NAME;
58
59  if ( !id )
60    return RTEMS_INVALID_ADDRESS;
61
62  /* Initialize core barrier attributes */
63  if ( _Attributes_Is_barrier_automatic( attribute_set ) ) {
64    the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
65    if ( maximum_waiters == 0 )
66      return RTEMS_INVALID_NUMBER;
67  } else
68    the_attributes.discipline = CORE_BARRIER_MANUAL_RELEASE;
69  the_attributes.maximum_count = maximum_waiters;
70
71  _Thread_Disable_dispatch();             /* prevents deletion */
72
73  the_barrier = _Barrier_Allocate();
74
75  if ( !the_barrier ) {
76    _Thread_Enable_dispatch();
77    return RTEMS_TOO_MANY;
78  }
79
80  the_barrier->attribute_set = attribute_set;
81
82  _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
83
84  _Objects_Open(
85    &_Barrier_Information,
86    &the_barrier->Object,
87    (Objects_Name) name
88  );
89
90  *id = the_barrier->Object.id;
91
92  _Thread_Enable_dispatch();
93  return RTEMS_SUCCESSFUL;
94}
Note: See TracBrowser for help on using the repository browser.