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/assert.h> |
---|
23 | #include <rtems/score/chainimpl.h> |
---|
24 | #include <rtems/score/sysstate.h> |
---|
25 | |
---|
26 | static Objects_Control *_Objects_Get_inactive( |
---|
27 | Objects_Information *information |
---|
28 | ) |
---|
29 | { |
---|
30 | return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive ); |
---|
31 | } |
---|
32 | |
---|
33 | Objects_Control *_Objects_Allocate_unprotected( |
---|
34 | Objects_Information *information |
---|
35 | ) |
---|
36 | { |
---|
37 | Objects_Control *the_object; |
---|
38 | |
---|
39 | _Assert( |
---|
40 | _Objects_Allocator_is_owner() |
---|
41 | || !_System_state_Is_up( _System_state_Get() ) |
---|
42 | ); |
---|
43 | |
---|
44 | /* |
---|
45 | * If the application is using the optional manager stubs and |
---|
46 | * still attempts to create the object, the information block |
---|
47 | * should be all zeroed out because it is in the BSS. So let's |
---|
48 | * check that code for this manager is even present. |
---|
49 | */ |
---|
50 | if ( information->object_size == 0 ) |
---|
51 | return NULL; |
---|
52 | |
---|
53 | /* |
---|
54 | * OK. The manager should be initialized and configured to have objects. |
---|
55 | * With any luck, it is safe to attempt to allocate an object. |
---|
56 | */ |
---|
57 | the_object = _Objects_Get_inactive( information ); |
---|
58 | |
---|
59 | if ( information->auto_extend ) { |
---|
60 | /* |
---|
61 | * If the list is empty then we are out of objects and need to |
---|
62 | * extend information base. |
---|
63 | */ |
---|
64 | |
---|
65 | if ( the_object == NULL ) { |
---|
66 | _Objects_Extend_information( information ); |
---|
67 | the_object = _Objects_Get_inactive( information ); |
---|
68 | } |
---|
69 | |
---|
70 | if ( the_object != NULL ) { |
---|
71 | Objects_Maximum block; |
---|
72 | |
---|
73 | block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM; |
---|
74 | block /= information->objects_per_block; |
---|
75 | |
---|
76 | information->inactive_per_block[ block ]--; |
---|
77 | information->inactive--; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | return the_object; |
---|
82 | } |
---|
83 | |
---|
84 | Objects_Control *_Objects_Allocate( Objects_Information *information ) |
---|
85 | { |
---|
86 | _RTEMS_Lock_allocator(); |
---|
87 | |
---|
88 | return _Objects_Allocate_unprotected( information ); |
---|
89 | } |
---|