source: rtems/cpukit/rtems/src/regioncreate.c @ ebe61382

4.104.114.95
Last change on this file since ebe61382 was 5700b804, checked in by Glenn Humphrey <glenn.humphrey@…>, on 11/27/07 at 17:38:11

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

  • rtems/src/regioncreate.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c: Restructed to move the OBJECTS_LOCAL case to the top of the switch statement, have a single exit with one call to _RTEMS_Unlock_allocator and eliminate the fall-through return of RTEMS_INTERNAL_ERROR. These changes produced simplier assembly code and allowed for complete test coverage.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  Region Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/score/object.h>
23#include <rtems/rtems/options.h>
24#include <rtems/rtems/region.h>
25#include <rtems/score/states.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/apimutex.h>
28
29/*PAGE
30 *
31 *  rtems_region_create
32 *
33 *  This directive creates a region of physical contiguous memory area
34 *  from which variable sized segments can be allocated.
35 *
36 *  Input parameters:
37 *    name             - user defined region name
38 *    starting_address - physical start address of region
39 *    length           - physical length in bytes
40 *    page_size        - page size in bytes
41 *    attribute_set    - region attributes
42 *    id               - address of region id to set
43 *
44 *  Output parameters:
45 *    id               - region id
46 *    RTEMS_SUCCESSFUL - if successful
47 *    error code       - if unsuccessful
48 */
49
50rtems_status_code rtems_region_create(
51  rtems_name          name,
52  void               *starting_address,
53  uint32_t            length,
54  uint32_t            page_size,
55  rtems_attribute     attribute_set,
56  Objects_Id         *id
57)
58{
59  rtems_status_code  return_status;
60  Region_Control    *the_region;
61
62  if ( !rtems_is_name_valid( name ) )
63    return RTEMS_INVALID_NAME;
64
65  if ( !starting_address )
66    return RTEMS_INVALID_ADDRESS;
67
68  if ( !id )
69    return RTEMS_INVALID_ADDRESS;
70
71  if ( !_Addresses_Is_aligned( starting_address ) )
72    return RTEMS_INVALID_ADDRESS;
73
74  _RTEMS_Lock_allocator();                      /* to prevent deletion */
75
76    the_region = _Region_Allocate();
77
78    if ( !the_region )
79      return_status = RTEMS_TOO_MANY;
80
81    else {
82
83      the_region->maximum_segment_size = _Heap_Initialize(
84        &the_region->Memory, starting_address, length, page_size
85      );
86
87      if ( !the_region->maximum_segment_size ) {
88        _Region_Free( the_region );
89        return_status = RTEMS_INVALID_SIZE;
90      }
91
92      else {
93
94        the_region->starting_address      = starting_address;
95        the_region->length                = length;
96        the_region->page_size             = page_size;
97        the_region->attribute_set         = attribute_set;
98        the_region->number_of_used_blocks = 0;
99
100        _Thread_queue_Initialize(
101          &the_region->Wait_queue,
102          _Attributes_Is_priority( attribute_set ) ?
103             THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
104          STATES_WAITING_FOR_SEGMENT,
105          RTEMS_TIMEOUT
106        );
107
108        _Objects_Open(
109          &_Region_Information,
110          &the_region->Object,
111          (Objects_Name) name
112        );
113
114        *id = the_region->Object.id;
115        return_status = RTEMS_SUCCESSFUL;
116      }
117    }
118
119  _RTEMS_Unlock_allocator();
120  return return_status;
121}
Note: See TracBrowser for help on using the repository browser.