RTEMS
Files | Classes | Typedefs | Variables
User Extension Handler

The User Extension Handler provides invocation of application dependent routines at critical points in the life of each thread and the system as a whole. More...

Files

file  userext.h
 User Extension Handler API.
 
file  userextdata.h
 User Extension Handler Data Structures.
 
file  userextimpl.h
 User Extension Handler API.
 
file  userext.c
 User Extension Handler implementation.
 
file  userextaddset.c
 User Extension Handler implementation.
 
file  userextiterate.c
 User Extension Iteration Helpers.
 
file  userextremoveset.c
 User Extension Handler implementation.
 

Classes

struct  User_extensions_Table
 User extension table. More...
 
struct  User_extensions_Switch_control
 Manages the switch callouts. More...
 
struct  User_extensions_Control
 Manages each user extension set. More...
 
struct  User_extensions_Iterator
 Chain iterator for dynamic user extensions. More...
 
struct  User_extensions_List
 
struct  User_extensions_Thread_create_context
 
struct  User_extensions_Fatal_context
 

Typedefs

typedef bool(* User_extensions_thread_create_extension) (struct _Thread_Control *executing, struct _Thread_Control *created)
 Task create extension. More...
 
typedef void(* User_extensions_thread_delete_extension) (struct _Thread_Control *executing, struct _Thread_Control *deleted)
 Task delete extension. More...
 
typedef void(* User_extensions_thread_start_extension) (struct _Thread_Control *executing, struct _Thread_Control *started)
 Task start extension. More...
 
typedef void(* User_extensions_thread_restart_extension) (struct _Thread_Control *executing, struct _Thread_Control *restarted)
 Task restart extension. More...
 
typedef void(* User_extensions_thread_switch_extension) (struct _Thread_Control *executing, struct _Thread_Control *heir)
 Task switch extension. More...
 
typedef void(* User_extensions_thread_begin_extension) (struct _Thread_Control *executing)
 Task begin extension. More...
 
typedef void(* User_extensions_thread_exitted_extension) (struct _Thread_Control *executing)
 Task exitted extension. More...
 
typedef void(* User_extensions_fatal_extension) (Internal_errors_Source source, bool always_set_to_false, Internal_errors_t code)
 Fatal error extension. More...
 
typedef void(* User_extensions_thread_terminate_extension) (struct _Thread_Control *terminated)
 Task termination extension. More...
 
typedef struct User_extensions_Iterator User_extensions_Iterator
 Chain iterator for dynamic user extensions. More...
 

Variables

const size_t _User_extensions_Initial_count
 The count of initial user extensions. More...
 
const User_extensions_Table _User_extensions_Initial_extensions []
 The table of initial user extensions. More...
 
User_extensions_Switch_control _User_extensions_Initial_switch_controls []
 A spare switch control for each initial user extension. More...
 
User_extensions_List _User_extensions_List
 List of active extensions.
 
Chain_Control _User_extensions_Switches_list
 List of active task switch extensions.
 

Extension Maintainance

typedef void(* User_extensions_Visitor) (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
 User extension visitor. More...
 
void _User_extensions_Handler_initialization (void)
 Initializes the user extensions handler.
 
void _User_extensions_Add_set (User_extensions_Control *extension)
 Adds a user extension. More...
 
static __inline__ void _User_extensions_Add_API_set (User_extensions_Control *extension)
 Adds a user extension. More...
 
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. More...
 
void _User_extensions_Remove_set (User_extensions_Control *extension)
 Removes a user extension. More...
 
void _User_extensions_Thread_create_visitor (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
 Creates a visitor. More...
 
void _User_extensions_Thread_delete_visitor (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
 Deletes a visitor. More...
 
void _User_extensions_Thread_start_visitor (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
 Starts a visitor. More...
 
void _User_extensions_Thread_restart_visitor (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
 Restarts a visitor. More...
 
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. More...
 
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. More...
 
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. More...
 
void _User_extensions_Thread_terminate_visitor (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)
 Terminates a visitor. More...
 
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. More...
 

Extension Callout Dispatcher

static bool _User_extensions_Thread_create (Thread_Control *created)
 Creates a thread. More...
 
static void _User_extensions_Thread_delete (Thread_Control *deleted)
 Deletes a thread. More...
 
static void _User_extensions_Thread_start (Thread_Control *started)
 Starts a thread. More...
 
static void _User_extensions_Thread_restart (Thread_Control *restarted)
 Restarts a thread. More...
 
static void _User_extensions_Thread_begin (Thread_Control *executing)
 Begins a thread. More...
 
static void _User_extensions_Thread_switch (Thread_Control *executing, Thread_Control *heir)
 Switches the thread from the executing to the heir. More...
 
static void _User_extensions_Thread_exitted (Thread_Control *executing)
 A user extension thread exitted. More...
 
static void _User_extensions_Fatal (Internal_errors_Source source, Internal_errors_t error)
 Forwards all visitors that there was a fatal failure. More...
 
static void _User_extensions_Thread_terminate (Thread_Control *executing)
 Terminates the executing thread. More...
 
static void _User_extensions_Acquire (ISR_lock_Context *lock_context)
 Disables interrupts and acquires the lock context. More...
 
static void _User_extensions_Release (ISR_lock_Context *lock_context)
 Releases the lock context and enables interrupts. More...
 
static void _User_extensions_Destroy_iterators (Thread_Control *the_thread)
 Destroys all user extension iterators of a thread. More...
 

Detailed Description

The User Extension Handler provides invocation of application dependent routines at critical points in the life of each thread and the system as a whole.

Typedef Documentation

◆ User_extensions_fatal_extension

typedef void( * User_extensions_fatal_extension) (Internal_errors_Source source, bool always_set_to_false, Internal_errors_t code)

Fatal error extension.

It corresponds to _Terminate() (used by the rtems_fatal() directive).

This extension should not call any RTEMS directives.

Parameters
[in]sourceThe fatal source indicating the subsystem the fatal condition originated in.
[in]always_set_to_falseThis parameter is always set to false and provided only for backward compatibility reasons.
[in]codeThe fatal error code. This value must be interpreted with respect to the source.

Definition at line 201 of file userext.h.

◆ User_extensions_Iterator

Chain iterator for dynamic user extensions.

Since user extensions may delete or restart the executing thread, we must clean up registered iterators.

See also
_User_extensions_Iterate(), _User_extensions_Destroy_iterators() and Thread_Control::last_user_extensions_iterator.

◆ User_extensions_thread_begin_extension

typedef void( * User_extensions_thread_begin_extension) (struct _Thread_Control *executing)

Task begin extension.

It corresponds to _Thread_Handler().

Thread dispatching is disabled. The executing thread is not the holder of the allocator mutex.

Parameters
[in]executingThe executing thread.

Definition at line 169 of file userext.h.

◆ User_extensions_thread_create_extension

typedef bool( * User_extensions_thread_create_extension) (struct _Thread_Control *executing, struct _Thread_Control *created)

Task create extension.

It corresponds to _Thread_Initialize() (used by the rtems_task_create() directive and pthread_create()).

It is invoked after the new thread has been completely initialized, but before it is placed on a ready chain.

Thread dispatching may be disabled. This depends on the context of the _Thread_Initialize() call. Thread dispatch is disabled during the creation of the idle thread and the initialization threads. It can be considered as an invalid API usage, if the application calls _Thread_Initialize() with disabled thread dispatching. Disabled thread dispatching is different from disabled preemption.

It can be assumed that the executing thread locked the allocator mutex. The only exception is the creation of the idle thread. In this case the allocator mutex is not locked. Since the allocator mutex allows nesting the normal memory allocation routines can be used.

Parameters
[in]executingThe executing thread.
[in]createdThe created thread.
Return values
trueSuccessful operation.
falseA thread create user extension will frequently attempt to allocate resources. If this allocation fails, then the extension should return false and the entire thread create operation will fail.

Definition at line 69 of file userext.h.

◆ User_extensions_thread_delete_extension

typedef void( * User_extensions_thread_delete_extension) (struct _Thread_Control *executing, struct _Thread_Control *deleted)

Task delete extension.

It corresponds to _Thread_Close() (used by the rtems_task_delete() directive, pthread_exit() and pthread_cancel()).

It is invoked before all resources of the thread are deleted. The executing and deleted arguments are never equal.

Thread dispatching is enabled. The executing thread locked the allocator mutex.

Parameters
[in]executingThe executing thread.
[in]deletedThe deleted thread.

Definition at line 89 of file userext.h.

◆ User_extensions_thread_exitted_extension

typedef void( * User_extensions_thread_exitted_extension) (struct _Thread_Control *executing)

Task exitted extension.

It corresponds to _Thread_Handler() after a return of the entry function.

Thread dispatching is disabled. The state of the allocator mutex is arbitrary.

Parameters
[in]executingThe executing thread.

Definition at line 183 of file userext.h.

◆ User_extensions_thread_restart_extension

typedef void( * User_extensions_thread_restart_extension) (struct _Thread_Control *executing, struct _Thread_Control *restarted)

Task restart extension.

It corresponds to _Thread_Restart() (used by the rtems_task_restart() directive).

It is invoked in the context of the restarted thread right before the execution context is reloaded. The executing and restarted arguments are always equal. The thread stack reflects the previous execution context.

Thread dispatching is enabled. The thread is not the holder of the allocator mutex. The thread life is protected. Thread restart and delete requests issued by restart extensions lead to recursion.

Parameters
[in]executingThe executing thread.
[in]restartedThe executing thread. Yes, the executing thread.

Definition at line 131 of file userext.h.

◆ User_extensions_thread_start_extension

typedef void( * User_extensions_thread_start_extension) (struct _Thread_Control *executing, struct _Thread_Control *started)

Task start extension.

It corresponds to _Thread_Start() (used by the rtems_task_start() directive).

It is invoked after the environment of the thread has been loaded and the thread has been made ready.

Thread dispatching is disabled. The executing thread is not the holder of the allocator mutex.

Parameters
[in]executingThe executing thread.
[in]startedThe started thread.

Definition at line 109 of file userext.h.

◆ User_extensions_thread_switch_extension

typedef void( * User_extensions_thread_switch_extension) (struct _Thread_Control *executing, struct _Thread_Control *heir)

Task switch extension.

It corresponds to _Thread_Dispatch().

It is invoked before the context switch from the executing to the heir thread.

Thread dispatching is disabled. The state of the allocator mutex is arbitrary. Interrupts are disabled and the per-CPU lock is acquired on SMP configurations.

The context switches initiated through _Thread_Start_multitasking() are not covered by this extension.

Parameters
[in]executingThe executing thread.
[in]heirThe heir thread.

Definition at line 154 of file userext.h.

◆ User_extensions_thread_terminate_extension

typedef void( * User_extensions_thread_terminate_extension) (struct _Thread_Control *terminated)

Task termination extension.

This extension is invoked by _Thread_Life_action_handler() in case a termination request is recognized.

It is invoked in the context of the terminated thread right before the thread dispatch to the heir thread. The POSIX cleanup and key destructors execute in this context.

Thread dispatching is enabled. The thread is not the holder of the allocator mutex. The thread life is protected. Thread restart and delete requests issued by terminate extensions lead to recursion.

Parameters
[in]terminatedThe terminated thread.

Definition at line 223 of file userext.h.

◆ User_extensions_Visitor

typedef void(* User_extensions_Visitor) (Thread_Control *executing, void *arg, const User_extensions_Table *callouts)

User extension visitor.

Parameters
[in,out]executingThe currently executing thread.
[in,out]argThe argument passed to _User_extensions_Iterate().
[in]calloutsThe current callouts.

Definition at line 143 of file userextimpl.h.

Function Documentation

◆ _User_extensions_Acquire()

static void _User_extensions_Acquire ( ISR_lock_Context lock_context)
inlinestatic

Disables interrupts and acquires the lock context.

Parameters
lock_contextThe lock context to acquire.

Definition at line 473 of file userextimpl.h.

◆ _User_extensions_Add_API_set()

static __inline__ void _User_extensions_Add_API_set ( User_extensions_Control extension)
static

Adds a user extension.

Parameters
extensionThe user extension to add.

Definition at line 104 of file userextimpl.h.

◆ _User_extensions_Add_set()

void _User_extensions_Add_set ( User_extensions_Control extension)

Adds a user extension.

Parameters
extensionThe user extension to add.

Definition at line 45 of file userextaddset.c.

◆ _User_extensions_Add_set_with_table()

static __inline__ void _User_extensions_Add_set_with_table ( User_extensions_Control extension,
const User_extensions_Table extension_table 
)
static

Adds a user extension with the given extension table as callouts.

Parameters
[in,out]extensionThe user extension to add.
extension_tableIs set as callouts for extension.

Definition at line 117 of file userextimpl.h.

◆ _User_extensions_Destroy_iterators()

static void _User_extensions_Destroy_iterators ( Thread_Control the_thread)
inlinestatic

Destroys all user extension iterators of a thread.

Parameters
[in,out]the_threadThe thread to destroy all user extension iterators of.

Definition at line 500 of file userextimpl.h.

◆ _User_extensions_Fatal()

static void _User_extensions_Fatal ( Internal_errors_Source  source,
Internal_errors_t  error 
)
inlinestatic

Forwards all visitors that there was a fatal failure.

Parameters
sourceThe error source.
errorThe error.

Definition at line 438 of file userextimpl.h.

◆ _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.

Parameters
executingThe currently executing thread.
argIs used as the user extension fatal context.
calloutsThe user extension table for the operation.

Definition at line 120 of file userextiterate.c.

◆ _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.

Parameters
[in,out]argThe argument passed to the visitor.
visitorThe visitor for each extension.
directionThe iteration direction for dynamic extensions.

Definition at line 149 of file userextiterate.c.

◆ _User_extensions_Release()

static void _User_extensions_Release ( ISR_lock_Context lock_context)
inlinestatic

Releases the lock context and enables interrupts.

Parameters
lock_contextThe lock context to release.

Definition at line 486 of file userextimpl.h.

◆ _User_extensions_Remove_set()

void _User_extensions_Remove_set ( User_extensions_Control extension)

Removes a user extension.

Parameters
extensionThe user extension to remove.

Definition at line 25 of file userextremoveset.c.

◆ _User_extensions_Thread_begin()

static void _User_extensions_Thread_begin ( Thread_Control executing)
inlinestatic

Begins a thread.

Parameters
createdThe thread to begin.

Definition at line 351 of file userextimpl.h.

◆ _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.

Parameters
executingThe currently executing thread.
argThis parameter is unused.
calloutsThe user extension table for the operation.

Definition at line 94 of file userextiterate.c.

◆ _User_extensions_Thread_create()

static bool _User_extensions_Thread_create ( Thread_Control created)
inlinestatic

Creates a thread.

Parameters
[out]createdThe thread to create.
Return values
trueThe operation succeeded.
falseThe operation failed.

Definition at line 291 of file userextimpl.h.

◆ _User_extensions_Thread_create_visitor()

void _User_extensions_Thread_create_visitor ( Thread_Control executing,
void *  arg,
const User_extensions_Table callouts 
)

Creates a visitor.

Parameters
executingThe currently executing thread.
[in,out]argIs used as the thread create context for the operation.
calloutsThe user extension table for the operation.

Definition at line 40 of file userextiterate.c.

◆ _User_extensions_Thread_delete()

static void _User_extensions_Thread_delete ( Thread_Control deleted)
inlinestatic

Deletes a thread.

Parameters
[out]createdThe thread to delete.

Definition at line 309 of file userextimpl.h.

◆ _User_extensions_Thread_delete_visitor()

void _User_extensions_Thread_delete_visitor ( Thread_Control executing,
void *  arg,
const User_extensions_Table callouts 
)

Deletes a visitor.

Parameters
executingThe currently executing thread.
[in,out]argParameter for the callout.
calloutsThe user extension table for the operation.

Definition at line 55 of file userextiterate.c.

◆ _User_extensions_Thread_exitted()

static void _User_extensions_Thread_exitted ( Thread_Control executing)
inlinestatic

A user extension thread exitted.

Parameters
createdThe thread.

Definition at line 423 of file userextimpl.h.

◆ _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.

Parameters
executingThe currently executing thread.
argThis parameter is unused.
calloutsThe user extension table for the operation.

Definition at line 107 of file userextiterate.c.

◆ _User_extensions_Thread_restart()

static void _User_extensions_Thread_restart ( Thread_Control restarted)
inlinestatic

Restarts a thread.

Parameters
createdThe thread to restart.

Definition at line 337 of file userextimpl.h.

◆ _User_extensions_Thread_restart_visitor()

void _User_extensions_Thread_restart_visitor ( Thread_Control executing,
void *  arg,
const User_extensions_Table callouts 
)

Restarts a visitor.

Parameters
executingThe currently executing thread.
argParameter for the callout.
calloutsThe user extension table for the operation.

Definition at line 81 of file userextiterate.c.

◆ _User_extensions_Thread_start()

static void _User_extensions_Thread_start ( Thread_Control started)
inlinestatic

Starts a thread.

Parameters
createdThe thread to start.

Definition at line 323 of file userextimpl.h.

◆ _User_extensions_Thread_start_visitor()

void _User_extensions_Thread_start_visitor ( Thread_Control executing,
void *  arg,
const User_extensions_Table callouts 
)

Starts a visitor.

Parameters
executingThe currently executing thread.
argParameter for the callout.
calloutsThe user extension table for the operation.

Definition at line 68 of file userextiterate.c.

◆ _User_extensions_Thread_switch()

static void _User_extensions_Thread_switch ( Thread_Control executing,
Thread_Control heir 
)
inlinestatic

Switches the thread from the executing to the heir.

Parameters
executingThe currently executing thread.
heirThe thread that will switch with executing.

Definition at line 366 of file userextimpl.h.

◆ _User_extensions_Thread_terminate()

static void _User_extensions_Thread_terminate ( Thread_Control executing)
inlinestatic

Terminates the executing thread.

Parameters
executingThe currently executing thread.

Definition at line 457 of file userextimpl.h.

◆ _User_extensions_Thread_terminate_visitor()

void _User_extensions_Thread_terminate_visitor ( Thread_Control executing,
void *  arg,
const User_extensions_Table callouts 
)

Terminates a visitor.

Parameters
executingThe currently executing thread.
argThis parameter is unused.
calloutsThe user extension table for the operation.

Definition at line 135 of file userextiterate.c.

Variable Documentation

◆ _User_extensions_Initial_count

const size_t _User_extensions_Initial_count

The count of initial user extensions.

Application provided via <rtems/confdefs.h>.

◆ _User_extensions_Initial_extensions

const User_extensions_Table _User_extensions_Initial_extensions[]

The table of initial user extensions.

Application provided via <rtems/confdefs.h>.

◆ _User_extensions_Initial_switch_controls

User_extensions_Switch_control _User_extensions_Initial_switch_controls[]

A spare switch control for each initial user extension.

Application provided via <rtems/confdefs.h>.