1 | /** |
---|
2 | * @file userext.inl |
---|
3 | * |
---|
4 | * This file contains the macro implementation of the inlined routines |
---|
5 | * from the User Extension Handler |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2004. |
---|
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.com/license/LICENSE. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef __USER_EXTENSIONS_inl |
---|
20 | #define __USER_EXTENSIONS_inl |
---|
21 | |
---|
22 | #include <rtems/score/wkspace.h> |
---|
23 | |
---|
24 | /** |
---|
25 | * @addtogroup ScoreUserExt |
---|
26 | * @{ |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | * This routine is used to add a user extension set to the active list. |
---|
31 | * |
---|
32 | * @note Must be before _User_extensions_Handler_initialization to |
---|
33 | * ensure proper inlining. |
---|
34 | */ |
---|
35 | |
---|
36 | RTEMS_INLINE_ROUTINE void _User_extensions_Add_set ( |
---|
37 | User_extensions_Control *the_extension, |
---|
38 | User_extensions_Table *extension_table |
---|
39 | ) |
---|
40 | { |
---|
41 | the_extension->Callouts = *extension_table; |
---|
42 | |
---|
43 | _Chain_Append( &_User_extensions_List, &the_extension->Node ); |
---|
44 | |
---|
45 | /* |
---|
46 | * If a switch handler is present, append it to the switch chain. |
---|
47 | */ |
---|
48 | |
---|
49 | if ( extension_table->thread_switch != NULL ) { |
---|
50 | the_extension->Switch.thread_switch = extension_table->thread_switch; |
---|
51 | _Chain_Append( &_User_extensions_Switches_list, &the_extension->Switch.Node ); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * This routine performs the initialization necessary for this handler. |
---|
57 | */ |
---|
58 | |
---|
59 | RTEMS_INLINE_ROUTINE void _User_extensions_Handler_initialization ( |
---|
60 | uint32_t number_of_extensions, |
---|
61 | User_extensions_Table *initial_extensions |
---|
62 | ) |
---|
63 | { |
---|
64 | User_extensions_Control *extension; |
---|
65 | uint32_t i; |
---|
66 | |
---|
67 | _Chain_Initialize_empty( &_User_extensions_List ); |
---|
68 | _Chain_Initialize_empty( &_User_extensions_Switches_list ); |
---|
69 | |
---|
70 | if ( initial_extensions ) { |
---|
71 | extension = (User_extensions_Control *) |
---|
72 | _Workspace_Allocate_or_fatal_error( |
---|
73 | number_of_extensions * sizeof( User_extensions_Control ) |
---|
74 | ); |
---|
75 | |
---|
76 | memset ( |
---|
77 | extension, |
---|
78 | 0, |
---|
79 | number_of_extensions * sizeof( User_extensions_Control ) |
---|
80 | ); |
---|
81 | |
---|
82 | for ( i = 0 ; i < number_of_extensions ; i++ ) { |
---|
83 | _User_extensions_Add_set (extension, &initial_extensions[i]); |
---|
84 | extension++; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * This routine is used to add an API extension set to the active list. |
---|
91 | */ |
---|
92 | |
---|
93 | RTEMS_INLINE_ROUTINE void _User_extensions_Add_API_set ( |
---|
94 | User_extensions_Control *the_extension |
---|
95 | ) |
---|
96 | { |
---|
97 | _Chain_Append( &_User_extensions_List, &the_extension->Node ); |
---|
98 | |
---|
99 | /* |
---|
100 | * If a switch handler is present, append it to the switch chain. |
---|
101 | */ |
---|
102 | |
---|
103 | if ( the_extension->Callouts.thread_switch != NULL ) { |
---|
104 | the_extension->Switch.thread_switch = the_extension->Callouts.thread_switch; |
---|
105 | _Chain_Append( |
---|
106 | &_User_extensions_Switches_list, &the_extension->Switch.Node ); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * This routine is used to remove a user extension set from the active list. |
---|
112 | */ |
---|
113 | |
---|
114 | RTEMS_INLINE_ROUTINE void _User_extensions_Remove_set ( |
---|
115 | User_extensions_Control *the_extension |
---|
116 | ) |
---|
117 | { |
---|
118 | _Chain_Extract( &the_extension->Node ); |
---|
119 | |
---|
120 | /* |
---|
121 | * If a switch handler is present, remove it. |
---|
122 | */ |
---|
123 | |
---|
124 | if ( the_extension->Callouts.thread_switch != NULL ) |
---|
125 | _Chain_Extract( &the_extension->Switch.Node ); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * This routine is used to invoke the user extension which |
---|
130 | * is invoked when a context switch occurs. |
---|
131 | */ |
---|
132 | |
---|
133 | RTEMS_INLINE_ROUTINE void _User_extensions_Thread_switch ( |
---|
134 | Thread_Control *executing, |
---|
135 | Thread_Control *heir |
---|
136 | ) |
---|
137 | { |
---|
138 | Chain_Node *the_node; |
---|
139 | User_extensions_Switch_control *the_extension_switch; |
---|
140 | |
---|
141 | for ( the_node = _User_extensions_Switches_list.first ; |
---|
142 | !_Chain_Is_tail( &_User_extensions_Switches_list, the_node ) ; |
---|
143 | the_node = the_node->next ) { |
---|
144 | |
---|
145 | the_extension_switch = (User_extensions_Switch_control *) the_node; |
---|
146 | |
---|
147 | (*the_extension_switch->thread_switch)( executing, heir ); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | /**@}*/ |
---|
152 | |
---|
153 | #endif |
---|
154 | /* end of include file */ |
---|