source: rtems/cpukit/rtems/src/partcreate.c @ e6b31b27

4.115
Last change on this file since e6b31b27 was 23fec9f0, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 13:16:12

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: 3.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Partition Create
5 * @ingroup ClassicPart Partitions
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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/rtems/partimpl.h>
22#include <rtems/rtems/attrimpl.h>
23#include <rtems/rtems/support.h>
24#include <rtems/score/threaddispatch.h>
25#include <rtems/score/sysstate.h>
26
27/*
28 *  rtems_partition_create
29 *
30 *  This directive creates a partiton of fixed sized buffers from the
31 *  given contiguous memory area.
32 *
33 *  Input parameters:
34 *    name             - user defined partition name
35 *    starting_address - physical start address of partition
36 *    length           - physical length in bytes
37 *    buffer_size      - size of buffers in bytes
38 *    attribute_set    - partition attributes
39 *    id               - pointer to partition id
40 *
41 *  Output parameters:
42 *    id               - partition id
43 *    RTEMS_SUCCESSFUL - if successful
44 *    error code       - if unsuccessful
45 */
46
47rtems_status_code rtems_partition_create(
48  rtems_name       name,
49  void            *starting_address,
50  uint32_t         length,
51  uint32_t         buffer_size,
52  rtems_attribute  attribute_set,
53  rtems_id        *id
54)
55{
56  Partition_Control *the_partition;
57
58  if ( !rtems_is_name_valid( name ) )
59    return RTEMS_INVALID_NAME;
60
61  if ( !starting_address )
62    return RTEMS_INVALID_ADDRESS;
63
64  if ( !id )
65    return RTEMS_INVALID_ADDRESS;
66
67  if ( length == 0 || buffer_size == 0 || length < buffer_size ||
68         !_Partition_Is_buffer_size_aligned( buffer_size ) )
69    return RTEMS_INVALID_SIZE;
70
71  if ( !_Addresses_Is_aligned( starting_address ) )
72     return RTEMS_INVALID_ADDRESS;
73
74#if defined(RTEMS_MULTIPROCESSING)
75  if ( _Attributes_Is_global( attribute_set ) &&
76       !_System_state_Is_multiprocessing )
77    return RTEMS_MP_NOT_CONFIGURED;
78#endif
79
80  the_partition = _Partition_Allocate();
81
82  if ( !the_partition ) {
83    _Objects_Allocator_unlock();
84    return RTEMS_TOO_MANY;
85  }
86
87#if defined(RTEMS_MULTIPROCESSING)
88  if ( _Attributes_Is_global( attribute_set ) &&
89       !( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
90                            the_partition->Object.id, false ) ) ) {
91    _Partition_Free( the_partition );
92    _Objects_Allocator_unlock();
93    return RTEMS_TOO_MANY;
94  }
95#endif
96
97  the_partition->starting_address      = starting_address;
98  the_partition->length                = length;
99  the_partition->buffer_size           = buffer_size;
100  the_partition->attribute_set         = attribute_set;
101  the_partition->number_of_used_blocks = 0;
102
103  _Chain_Initialize( &the_partition->Memory, starting_address,
104                        length / buffer_size, buffer_size );
105
106  _Objects_Open(
107    &_Partition_Information,
108    &the_partition->Object,
109    (Objects_Name) name
110  );
111
112  *id = the_partition->Object.id;
113#if defined(RTEMS_MULTIPROCESSING)
114  if ( _Attributes_Is_global( attribute_set ) )
115    _Partition_MP_Send_process_packet(
116      PARTITION_MP_ANNOUNCE_CREATE,
117      the_partition->Object.id,
118      name,
119      0                  /* Not used */
120    );
121#endif
122
123  _Objects_Allocator_unlock();
124  return RTEMS_SUCCESSFUL;
125}
Note: See TracBrowser for help on using the repository browser.