RTEMS: cpukit/include/rtems/score/userextimpl.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
userextimpl.h
Go to the documentation of this file.
1
9/*
10 * COPYRIGHT (c) 1989-2009.
11 * On-Line Applications Research Corporation (OAR).
12 *
13 * The license and distribution terms for this file may be
14 * found in the file LICENSE in this distribution or at
15 * http://www.rtems.org/license/LICENSE.
16 */
17
18#ifndef _RTEMS_SCORE_USEREXTIMPL_H
19#define _RTEMS_SCORE_USEREXTIMPL_H
20
21#include <rtems/score/userextdata.h>
22#include <rtems/score/chainimpl.h>
23#include <rtems/score/isrlock.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/percpu.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
46 typedef struct User_extensions_Iterator {
47 Chain_Iterator Iterator;
48 struct User_extensions_Iterator *previous;
49} User_extensions_Iterator;
50
51 typedef struct {
55 Chain_Control Active;
56
60 Chain_Iterator_registry Iterators;
61
66 ISR_LOCK_MEMBER( Lock )
67} User_extensions_List;
68
72extern User_extensions_List _User_extensions_List;
73
77extern Chain_Control _User_extensions_Switches_list;
78
88void _User_extensions_Handler_initialization( void );
89
95void _User_extensions_Add_set(
96 User_extensions_Control *extension
97);
98
104 RTEMS_INLINE_ROUTINE void _User_extensions_Add_API_set(
105 User_extensions_Control *extension
106)
107{
108 _User_extensions_Add_set( extension );
109}
110
117 RTEMS_INLINE_ROUTINE void _User_extensions_Add_set_with_table(
118 User_extensions_Control *extension,
119 const User_extensions_Table *extension_table
120)
121{
122 extension->Callouts = *extension_table;
123
124 _User_extensions_Add_set( extension );
125}
126
132void _User_extensions_Remove_set(
133 User_extensions_Control *extension
134);
135
143 typedef void (*User_extensions_Visitor)(
144 Thread_Control *executing,
145 void *arg,
146 const User_extensions_Table *callouts
147);
148
149 typedef struct {
150 Thread_Control *created;
151 bool ok;
152} User_extensions_Thread_create_context;
153
161void _User_extensions_Thread_create_visitor(
162 Thread_Control *executing,
163 void *arg,
164 const User_extensions_Table *callouts
165);
166
174void _User_extensions_Thread_delete_visitor(
175 Thread_Control *executing,
176 void *arg,
177 const User_extensions_Table *callouts
178);
179
187void _User_extensions_Thread_start_visitor(
188 Thread_Control *executing,
189 void *arg,
190 const User_extensions_Table *callouts
191);
192
200void _User_extensions_Thread_restart_visitor(
201 Thread_Control *executing,
202 void *arg,
203 const User_extensions_Table *callouts
204);
205
213void _User_extensions_Thread_begin_visitor(
214 Thread_Control *executing,
215 void *arg,
216 const User_extensions_Table *callouts
217);
218
226void _User_extensions_Thread_exitted_visitor(
227 Thread_Control *executing,
228 void *arg,
229 const User_extensions_Table *callouts
230);
231
232 typedef struct {
233 Internal_errors_Source source;
234 Internal_errors_t error;
235} User_extensions_Fatal_context;
236
244void _User_extensions_Fatal_visitor(
245 Thread_Control *executing,
246 void *arg,
247 const User_extensions_Table *callouts
248);
249
257void _User_extensions_Thread_terminate_visitor(
258 Thread_Control *executing,
259 void *arg,
260 const User_extensions_Table *callouts
261);
262
270void _User_extensions_Iterate(
271 void *arg,
272 User_extensions_Visitor visitor,
273 Chain_Iterator_direction direction
274);
275
291static inline bool _User_extensions_Thread_create( Thread_Control *created )
292{
293 User_extensions_Thread_create_context ctx = { created, true };
294
295 _User_extensions_Iterate(
296 &ctx,
297 _User_extensions_Thread_create_visitor,
298 CHAIN_ITERATOR_FORWARD
299 );
300
301 return ctx.ok;
302}
303
309static inline void _User_extensions_Thread_delete( Thread_Control *deleted )
310{
311 _User_extensions_Iterate(
312 deleted,
313 _User_extensions_Thread_delete_visitor,
314 CHAIN_ITERATOR_BACKWARD
315 );
316}
317
323static inline void _User_extensions_Thread_start( Thread_Control *started )
324{
325 _User_extensions_Iterate(
326 started,
327 _User_extensions_Thread_start_visitor,
328 CHAIN_ITERATOR_FORWARD
329 );
330}
331
337static inline void _User_extensions_Thread_restart( Thread_Control *restarted )
338{
339 _User_extensions_Iterate(
340 restarted,
341 _User_extensions_Thread_restart_visitor,
342 CHAIN_ITERATOR_FORWARD
343 );
344}
345
351static inline void _User_extensions_Thread_begin( Thread_Control *executing )
352{
353 _User_extensions_Iterate(
354 executing,
355 _User_extensions_Thread_begin_visitor,
356 CHAIN_ITERATOR_FORWARD
357 );
358}
359
366static inline void _User_extensions_Thread_switch(
367 Thread_Control *executing,
368 Thread_Control *heir
369)
370{
371 const Chain_Control *chain;
372 const Chain_Node *tail;
373 const Chain_Node *node;
374
375 chain = &_User_extensions_Switches_list;
376 tail = _Chain_Immutable_tail( chain );
377 node = _Chain_Immutable_first( chain );
378
379 if ( node != tail ) {
380#if defined(RTEMS_SMP)
381 ISR_lock_Context lock_context;
382 Per_CPU_Control *cpu_self;
383
384 cpu_self = _Per_CPU_Get();
385
386 _ISR_lock_ISR_disable( &lock_context );
387 _Per_CPU_Acquire( cpu_self, &lock_context );
388
389 executing = cpu_self->ancestor;
390 cpu_self->ancestor = heir;
391 node = _Chain_Immutable_first( chain );
392
393 /*
394 * An executing thread equal to the heir thread may happen in two
395 * situations. Firstly, in case context switch extensions are created after
396 * system initialization. Secondly, during a thread self restart.
397 */
398 if ( executing != heir ) {
399#endif
400
401 while ( node != tail ) {
402 const User_extensions_Switch_control *extension;
403
404 extension = (const User_extensions_Switch_control *) node;
405 node = _Chain_Immutable_next( node );
406 (*extension->thread_switch)( executing, heir );
407 }
408
409#if defined(RTEMS_SMP)
410 }
411
412 _Per_CPU_Release( cpu_self, &lock_context );
413 _ISR_lock_ISR_enable( &lock_context );
414#endif
415 }
416}
417
423static inline void _User_extensions_Thread_exitted( Thread_Control *executing )
424{
425 _User_extensions_Iterate(
426 executing,
427 _User_extensions_Thread_exitted_visitor,
428 CHAIN_ITERATOR_FORWARD
429 );
430}
431
438static inline void _User_extensions_Fatal(
439 Internal_errors_Source source,
440 Internal_errors_t error
441)
442{
443 User_extensions_Fatal_context ctx = { source, error };
444
445 _User_extensions_Iterate(
446 &ctx,
447 _User_extensions_Fatal_visitor,
448 CHAIN_ITERATOR_FORWARD
449 );
450}
451
457static inline void _User_extensions_Thread_terminate(
458 Thread_Control *executing
459)
460{
461 _User_extensions_Iterate(
462 executing,
463 _User_extensions_Thread_terminate_visitor,
464 CHAIN_ITERATOR_BACKWARD
465 );
466}
467
473static inline void _User_extensions_Acquire( ISR_lock_Context *lock_context )
474{
475 _ISR_lock_ISR_disable_and_acquire(
476 &_User_extensions_List.Lock,
477 lock_context
478 );
479}
480
486static inline void _User_extensions_Release( ISR_lock_Context *lock_context )
487{
488 _ISR_lock_Release_and_ISR_enable(
489 &_User_extensions_List.Lock,
490 lock_context
491 );
492}
493
500static inline void _User_extensions_Destroy_iterators(
501 Thread_Control *the_thread
502)
503{
504 ISR_lock_Context lock_context;
505 User_extensions_Iterator *iter;
506
507 _User_extensions_Acquire( &lock_context );
508
509 iter = the_thread->last_user_extensions_iterator;
510
511 while ( iter != NULL ) {
512 _Chain_Iterator_destroy( &iter->Iterator );
513 iter = iter->previous;
514 }
515
516 _User_extensions_Release( &lock_context );
517}
518
523#ifdef __cplusplus
524}
525#endif
526
527#endif
528/* end of include file */
NULL
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
chainimpl.h
Chain Handler API.
RTEMS_INLINE_ROUTINE
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
_Chain_Immutable_first
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_first(const Chain_Control *the_chain)
Returns pointer to immutable chain's first node.
Definition: chainimpl.h:277
_Chain_Immutable_tail
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_tail(const Chain_Control *the_chain)
Returns pointer to immutable chain tail.
Definition: chainimpl.h:243
_Chain_Immutable_next
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_next(const Chain_Node *the_node)
Returns pointer to the immutable next node from this node.
Definition: chainimpl.h:343
Chain_Iterator_direction
Chain_Iterator_direction
The chain iterator direction.
Definition: chainimpl.h:884
_Chain_Iterator_destroy
RTEMS_INLINE_ROUTINE void _Chain_Iterator_destroy(Chain_Iterator *the_iterator)
Destroys the iterator.
Definition: chainimpl.h:1121
CHAIN_ITERATOR_BACKWARD
@ CHAIN_ITERATOR_BACKWARD
Iteration from tail to head.
Definition: chainimpl.h:893
CHAIN_ITERATOR_FORWARD
@ CHAIN_ITERATOR_FORWARD
Iteration from head to tail.
Definition: chainimpl.h:888
ISR_LOCK_MEMBER
#define ISR_LOCK_MEMBER(_designator)
Defines an ISR lock member.
Definition: isrlock.h:89
_ISR_lock_ISR_enable
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:419
_ISR_lock_ISR_disable
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:398
_ISR_lock_Release_and_ISR_enable
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:263
_ISR_lock_ISR_disable_and_acquire
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:238
Internal_errors_Source
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:47
_User_extensions_Thread_create_visitor
void _User_extensions_Thread_create_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Creates a visitor.
Definition: userextiterate.c:40
_User_extensions_Thread_delete_visitor
void _User_extensions_Thread_delete_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Deletes a visitor.
Definition: userextiterate.c:55
_User_extensions_Thread_start_visitor
void _User_extensions_Thread_start_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Starts a visitor.
Definition: userextiterate.c:68
_User_extensions_Iterate
void _User_extensions_Iterate(void *arg, User_extensions_Visitor visitor, Chain_Iterator_direction direction)
Iterates through all user extensions and calls the visitor for each.
Definition: userextiterate.c:149
_User_extensions_Remove_set
void _User_extensions_Remove_set(User_extensions_Control *extension)
Removes a user extension.
Definition: userextremoveset.c:25
_User_extensions_Thread_restart_visitor
void _User_extensions_Thread_restart_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Restarts a visitor.
Definition: userextiterate.c:81
User_extensions_Visitor
void(* User_extensions_Visitor)(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
User extension visitor.
Definition: userextimpl.h:143
_User_extensions_Thread_terminate_visitor
void _User_extensions_Thread_terminate_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Terminates a visitor.
Definition: userextiterate.c:135
_User_extensions_Fatal_visitor
void _User_extensions_Fatal_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Calls the fatal function of the thread callout for the visitor.
Definition: userextiterate.c:120
_User_extensions_Thread_begin_visitor
void _User_extensions_Thread_begin_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Calls the begin function of the thread callout for the visitor.
Definition: userextiterate.c:94
_User_extensions_Thread_exitted_visitor
void _User_extensions_Thread_exitted_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Calls the exitted function of the thread callout for the visitor.
Definition: userextiterate.c:107
_User_extensions_List
User_extensions_List _User_extensions_List
List of active extensions.
Definition: userextiterate.c:31
_User_extensions_Switches_list
Chain_Control _User_extensions_Switches_list
List of active task switch extensions.
_User_extensions_Add_set_with_table
RTEMS_INLINE_ROUTINE void _User_extensions_Add_set_with_table(User_extensions_Control *extension, const User_extensions_Table *extension_table)
Adds a user extension with the given extension table as callouts.
Definition: userextimpl.h:117
_User_extensions_Handler_initialization
void _User_extensions_Handler_initialization(void)
Initializes the user extensions handler.
Definition: userext.c:24
_User_extensions_Add_API_set
RTEMS_INLINE_ROUTINE void _User_extensions_Add_API_set(User_extensions_Control *extension)
Adds a user extension.
Definition: userextimpl.h:104
_User_extensions_Add_set
void _User_extensions_Add_set(User_extensions_Control *extension)
Adds a user extension.
Definition: userextaddset.c:45
isrlock.h
ISR Locks.
percpu.h
thread.h
Constants and Structures Related with the Thread Control Block.
Chain_Iterator_registry
A registry for chain iterators.
Definition: chainimpl.h:934
Chain_Iterator
A chain iterator which is updated during node extraction if it is properly registered.
Definition: chainimpl.h:902
Chain_Node_struct
Definition: chain.h:68
ISR_lock_Context
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Per_CPU_Control
Per CPU Core Structure.
Definition: percpu.h:347
User_extensions_Control
Manages each user extension set.
Definition: userextdata.h:50
User_extensions_Fatal_context
Definition: userextimpl.h:232
User_extensions_Iterator
Chain iterator for dynamic user extensions.
Definition: userextimpl.h:46
User_extensions_List
Definition: userextimpl.h:51
User_extensions_List::Iterators
Chain_Iterator_registry Iterators
Chain iterator registration.
Definition: userextimpl.h:60
User_extensions_List::Active
Chain_Control Active
Active dynamically added user extensions.
Definition: userextimpl.h:55
User_extensions_Switch_control
Manages the switch callouts.
Definition: userextdata.h:39
User_extensions_Table
User extension table.
Definition: userext.h:232
User_extensions_Thread_create_context
Definition: userextimpl.h:149
_Thread_Control
Definition: thread.h:732
_Thread_Control::last_user_extensions_iterator
struct User_extensions_Iterator * last_user_extensions_iterator
LIFO list of user extensions iterators.
Definition: thread.h:876
Chain_Control
Definition: chain.h:86
userextdata.h
User Extension Handler Data Structures.