source: rtems/cpukit/rtems/src/barriercreate.c @ 66cb142

Last change on this file since 66cb142 was 23fec9f, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 27, 2014 at 1:16:12 PM

score: PR2152: Use allocator mutex for objects

Use allocator mutex for objects allocate/free. This prevents that the
thread dispatch latency depends on the workspace/heap fragmentation.

  • Property mode set to 100644
File size: 2.2 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  the_barrier = _Barrier_Allocate();
72
73  if ( !the_barrier ) {
74    _Objects_Allocator_unlock();
75    return RTEMS_TOO_MANY;
76  }
77
78  the_barrier->attribute_set = attribute_set;
79
80  _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
81
82  _Objects_Open(
83    &_Barrier_Information,
84    &the_barrier->Object,
85    (Objects_Name) name
86  );
87
88  *id = the_barrier->Object.id;
89
90  _Objects_Allocator_unlock();
91  return RTEMS_SUCCESSFUL;
92}
Note: See TracBrowser for help on using the repository browser.