1 | /* |
---|
2 | * Object Handler |
---|
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/score/address.h> |
---|
21 | #include <rtems/score/chain.h> |
---|
22 | #include <rtems/score/object.h> |
---|
23 | #if defined(RTEMS_MULTIPROCESSING) |
---|
24 | #include <rtems/score/objectmp.h> |
---|
25 | #endif |
---|
26 | #include <rtems/score/thread.h> |
---|
27 | #include <rtems/score/wkspace.h> |
---|
28 | #include <rtems/score/sysstate.h> |
---|
29 | #include <rtems/score/isr.h> |
---|
30 | |
---|
31 | /*PAGE |
---|
32 | * |
---|
33 | * _Objects_Allocate |
---|
34 | * |
---|
35 | * DESCRIPTION: |
---|
36 | * |
---|
37 | * This function allocates a object control block from |
---|
38 | * the inactive chain of free object control blocks. |
---|
39 | */ |
---|
40 | |
---|
41 | Objects_Control *_Objects_Allocate( |
---|
42 | Objects_Information *information |
---|
43 | ) |
---|
44 | { |
---|
45 | Objects_Control *the_object; |
---|
46 | |
---|
47 | /* |
---|
48 | * If the application is using the optional manager stubs and |
---|
49 | * still attempts to create the object, the information block |
---|
50 | * should be all zeroed out because it is in the BSS. So let's |
---|
51 | * check that code for this manager is even present. |
---|
52 | */ |
---|
53 | if ( information->size == 0 ) |
---|
54 | return NULL; |
---|
55 | |
---|
56 | /* |
---|
57 | * OK. The manager should be initialized and configured to have objects. |
---|
58 | * With any luck, it is safe to attempt to allocate an object. |
---|
59 | */ |
---|
60 | the_object = (Objects_Control *) _Chain_Get( &information->Inactive ); |
---|
61 | |
---|
62 | if ( information->auto_extend ) { |
---|
63 | /* |
---|
64 | * If the list is empty then we are out of objects and need to |
---|
65 | * extend information base. |
---|
66 | */ |
---|
67 | |
---|
68 | if ( !the_object ) { |
---|
69 | _Objects_Extend_information( information ); |
---|
70 | the_object = (Objects_Control *) _Chain_Get( &information->Inactive ); |
---|
71 | } |
---|
72 | |
---|
73 | if ( the_object ) { |
---|
74 | uint32_t block; |
---|
75 | |
---|
76 | block = _Objects_Get_index( the_object->id ) - |
---|
77 | _Objects_Get_index( information->minimum_id ); |
---|
78 | block /= information->allocation_size; |
---|
79 | |
---|
80 | information->inactive_per_block[ block ]--; |
---|
81 | information->inactive--; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | return the_object; |
---|
86 | } |
---|