RTEMS
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 
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
28 extern "C" {
29 #endif
30 
46 typedef struct User_extensions_Iterator {
47  Chain_Iterator Iterator;
48  struct User_extensions_Iterator *previous;
50 
51 typedef struct {
56 
61 
66  ISR_LOCK_MEMBER( Lock )
68 
73 
78 
89 
96  User_extensions_Control *extension
97 );
98 
105  User_extensions_Control *extension
106 )
107 {
108  _User_extensions_Add_set( extension );
109 }
110 
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 
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;
153 
162  Thread_Control *executing,
163  void *arg,
164  const User_extensions_Table *callouts
165 );
166 
175  Thread_Control *executing,
176  void *arg,
177  const User_extensions_Table *callouts
178 );
179 
188  Thread_Control *executing,
189  void *arg,
190  const User_extensions_Table *callouts
191 );
192 
201  Thread_Control *executing,
202  void *arg,
203  const User_extensions_Table *callouts
204 );
205 
214  Thread_Control *executing,
215  void *arg,
216  const User_extensions_Table *callouts
217 );
218 
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;
236 
245  Thread_Control *executing,
246  void *arg,
247  const User_extensions_Table *callouts
248 );
249 
258  Thread_Control *executing,
259  void *arg,
260  const User_extensions_Table *callouts
261 );
262 
271  void *arg,
272  User_extensions_Visitor visitor,
273  Chain_Iterator_direction direction
274 );
275 
291 static inline bool _User_extensions_Thread_create( Thread_Control *created )
292 {
293  User_extensions_Thread_create_context ctx = { created, true };
294 
296  &ctx,
299  );
300 
301  return ctx.ok;
302 }
303 
309 static inline void _User_extensions_Thread_delete( Thread_Control *deleted )
310 {
312  deleted,
315  );
316 }
317 
323 static inline void _User_extensions_Thread_start( Thread_Control *started )
324 {
326  started,
329  );
330 }
331 
337 static inline void _User_extensions_Thread_restart( Thread_Control *restarted )
338 {
340  restarted,
343  );
344 }
345 
351 static inline void _User_extensions_Thread_begin( Thread_Control *executing )
352 {
354  executing,
357  );
358 }
359 
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 
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 
423 static inline void _User_extensions_Thread_exitted( Thread_Control *executing )
424 {
426  executing,
429  );
430 }
431 
438 static 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 
446  &ctx,
449  );
450 }
451 
458  Thread_Control *executing
459 )
460 {
462  executing,
465  );
466 }
467 
473 static inline void _User_extensions_Acquire( ISR_lock_Context *lock_context )
474 {
476  &_User_extensions_List.Lock,
477  lock_context
478  );
479 }
480 
486 static inline void _User_extensions_Release( ISR_lock_Context *lock_context )
487 {
489  &_User_extensions_List.Lock,
490  lock_context
491  );
492 }
493 
501  Thread_Control *the_thread
502 )
503 {
504  ISR_lock_Context lock_context;
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 */
Manages the switch callouts.
Definition: userextdata.h:39
static void _User_extensions_Thread_terminate(Thread_Control *executing)
Terminates the executing thread.
Definition: userextimpl.h:457
static __inline__ void _Chain_Iterator_destroy(Chain_Iterator *the_iterator)
Destroys the iterator.
Definition: chainimpl.h:1121
User Extension Handler Data Structures.
A chain iterator which is updated during node extraction if it is properly registered.
Definition: chainimpl.h:902
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:257
static void _User_extensions_Thread_restart(Thread_Control *restarted)
Restarts a thread.
Definition: userextimpl.h:337
static void _User_extensions_Fatal(Internal_errors_Source source, Internal_errors_t error)
Forwards all visitors that there was a fatal failure.
Definition: userextimpl.h:438
void _User_extensions_Thread_delete_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Deletes a 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.
static void _User_extensions_Thread_delete(Thread_Control *deleted)
Deletes a thread.
Definition: userextimpl.h:309
Chain iterator for dynamic user extensions.
Definition: userextimpl.h:46
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:416
Chain_Control _User_extensions_Switches_list
List of active task switch extensions.
struct _Thread_Control * ancestor
The ancestor of the executing thread.
Definition: percpu.h:536
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.
static bool _User_extensions_Thread_create(Thread_Control *created)
Creates a thread.
Definition: userextimpl.h:291
struct User_extensions_Iterator * last_user_extensions_iterator
LIFO list of user extensions iterators.
Definition: thread.h:869
void _User_extensions_Handler_initialization(void)
Initializes the user extensions handler.
Definition: userext.c:24
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:47
static void _User_extensions_Thread_switch(Thread_Control *executing, Thread_Control *heir)
Switches the thread from the executing to the heir.
Definition: userextimpl.h:366
void _User_extensions_Thread_restart_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Restarts a 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.
struct User_extensions_Iterator User_extensions_Iterator
Chain iterator for dynamic user extensions.
User_extensions_List _User_extensions_List
List of active extensions.
#define ISR_LOCK_MEMBER(_designator)
Defines an ISR lock member.
Definition: isrlock.h:87
static void _User_extensions_Destroy_iterators(Thread_Control *the_thread)
Destroys all user extension iterators of a thread.
Definition: userextimpl.h:500
Per CPU Core Structure.
Definition: percpu.h:347
void _User_extensions_Add_set(User_extensions_Control *extension)
Adds a user extension.
Definition: userextaddset.c:45
void _User_extensions_Remove_set(User_extensions_Control *extension)
Removes a user extension.
static __inline__ 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
static __inline__ 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
static void _User_extensions_Thread_begin(Thread_Control *executing)
Begins a thread.
Definition: userextimpl.h:351
Chain Handler API.
static void _User_extensions_Release(ISR_lock_Context *lock_context)
Releases the lock context and enables interrupts.
Definition: userextimpl.h:486
static void _User_extensions_Thread_start(Thread_Control *started)
Starts a thread.
Definition: userextimpl.h:323
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:232
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.
void(* User_extensions_Visitor)(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
User extension visitor.
Definition: userextimpl.h:143
static __inline__ const Chain_Node * _Chain_Immutable_first(const Chain_Control *the_chain)
Returns pointer to immutable chain&#39;s first node.
Definition: chainimpl.h:277
Iteration from head to tail.
Definition: chainimpl.h:888
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:392
User extension table.
Definition: userext.h:230
Chain_Iterator_registry Iterators
Chain iterator registration.
Definition: userextimpl.h:60
Manages each user extension set.
Definition: userextdata.h:50
Chain_Control Active
Active dynamically added user extensions.
Definition: userextimpl.h:55
void _User_extensions_Thread_create_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Creates a visitor.
void _User_extensions_Thread_terminate_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Terminates a visitor.
static __inline__ void _User_extensions_Add_API_set(User_extensions_Control *extension)
Adds a user extension.
Definition: userextimpl.h:104
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Chain_Iterator_direction
The chain iterator direction.
Definition: chainimpl.h:884
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
static void _User_extensions_Acquire(ISR_lock_Context *lock_context)
Disables interrupts and acquires the lock context.
Definition: userextimpl.h:473
Iteration from tail to head.
Definition: chainimpl.h:893
void _User_extensions_Thread_start_visitor(Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
Starts a visitor.
Constants and Structures Related with the Thread Control Block.
ISR Locks.
static void _User_extensions_Thread_exitted(Thread_Control *executing)
A user extension thread exitted.
Definition: userextimpl.h:423
static __inline__ const Chain_Node * _Chain_Immutable_tail(const Chain_Control *the_chain)
Returns pointer to immutable chain tail.
Definition: chainimpl.h:243
A registry for chain iterators.
Definition: chainimpl.h:934