1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Allocate Object |
---|
5 | * @ingroup ScoreObject |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
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/score/objectimpl.h> |
---|
22 | #include <rtems/score/chainimpl.h> |
---|
23 | |
---|
24 | /* #define RTEMS_DEBUG_OBJECT_ALLOCATION */ |
---|
25 | |
---|
26 | #if defined(RTEMS_DEBUG_OBJECT_ALLOCATION) |
---|
27 | #include <rtems/bspIo.h> |
---|
28 | #endif |
---|
29 | |
---|
30 | Objects_Control *_Objects_Allocate( |
---|
31 | Objects_Information *information |
---|
32 | ) |
---|
33 | { |
---|
34 | Objects_Control *the_object; |
---|
35 | |
---|
36 | /* |
---|
37 | * If the application is using the optional manager stubs and |
---|
38 | * still attempts to create the object, the information block |
---|
39 | * should be all zeroed out because it is in the BSS. So let's |
---|
40 | * check that code for this manager is even present. |
---|
41 | */ |
---|
42 | if ( information->size == 0 ) |
---|
43 | return NULL; |
---|
44 | |
---|
45 | /* |
---|
46 | * OK. The manager should be initialized and configured to have objects. |
---|
47 | * With any luck, it is safe to attempt to allocate an object. |
---|
48 | */ |
---|
49 | the_object = (Objects_Control *) _Chain_Get( &information->Inactive ); |
---|
50 | |
---|
51 | if ( information->auto_extend ) { |
---|
52 | /* |
---|
53 | * If the list is empty then we are out of objects and need to |
---|
54 | * extend information base. |
---|
55 | */ |
---|
56 | |
---|
57 | if ( !the_object ) { |
---|
58 | _Objects_Extend_information( information ); |
---|
59 | the_object = (Objects_Control *) _Chain_Get( &information->Inactive ); |
---|
60 | } |
---|
61 | |
---|
62 | if ( the_object ) { |
---|
63 | uint32_t block; |
---|
64 | |
---|
65 | block = (uint32_t) _Objects_Get_index( the_object->id ) - |
---|
66 | _Objects_Get_index( information->minimum_id ); |
---|
67 | block /= information->allocation_size; |
---|
68 | |
---|
69 | information->inactive_per_block[ block ]--; |
---|
70 | information->inactive--; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | #if defined(RTEMS_DEBUG_OBJECT_ALLOCATION) |
---|
75 | if ( !the_object ) { |
---|
76 | printk( |
---|
77 | "OBJECT ALLOCATION FAILURE! API/Class %d/%d\n", |
---|
78 | information->the_api, |
---|
79 | information->the_class |
---|
80 | ); |
---|
81 | } |
---|
82 | #endif |
---|
83 | |
---|
84 | return the_object; |
---|
85 | } |
---|