Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSScoreUserExt
0007  *
0008  * @brief This header file provides interfaces of the
0009  *   @ref RTEMSScoreUserExt which are used by the implementation and the
0010  *   @ref RTEMSImplApplConfig.
0011  */
0012 
0013 /*
0014  *  COPYRIGHT (c) 1989-2009.
0015  *  On-Line Applications Research Corporation (OAR).
0016  *
0017  * Redistribution and use in source and binary forms, with or without
0018  * modification, are permitted provided that the following conditions
0019  * are met:
0020  * 1. Redistributions of source code must retain the above copyright
0021  *    notice, this list of conditions and the following disclaimer.
0022  * 2. Redistributions in binary form must reproduce the above copyright
0023  *    notice, this list of conditions and the following disclaimer in the
0024  *    documentation and/or other materials provided with the distribution.
0025  *
0026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0036  * POSSIBILITY OF SUCH DAMAGE.
0037  */
0038 
0039 #ifndef _RTEMS_SCORE_USEREXT_H
0040 #define _RTEMS_SCORE_USEREXT_H
0041 
0042 #include <rtems/score/interr.h>
0043 
0044 #ifdef __cplusplus
0045 extern "C" {
0046 #endif
0047 
0048 struct _Thread_Control;
0049 
0050 /**
0051  * @defgroup RTEMSScoreUserExt User Extensions Handler
0052  *
0053  * @ingroup RTEMSScore
0054  *
0055  * @brief This group contains the User Extensions Handler implementation.
0056  *
0057  * This handler provides the invocation of application dependent routines at
0058  * critical points in the life of each thread and the system as a whole.
0059  *
0060  * @{
0061  */
0062 
0063 /**
0064  * @brief Task create extension.
0065  *
0066  * It corresponds to _Thread_Initialize() (used by the rtems_task_create()
0067  * directive and pthread_create()).
0068  *
0069  * It is invoked after the new thread has been completely initialized, but
0070  * before it is placed on a ready chain.
0071  *
0072  * Thread dispatching may be disabled.  This depends on the context of the
0073  * _Thread_Initialize() call.  Thread dispatch is disabled during the creation
0074  * of the idle thread and the initialization threads.  It can be considered as
0075  * an invalid API usage, if the application calls _Thread_Initialize() with
0076  * disabled thread dispatching.  Disabled thread dispatching is different from
0077  * disabled preemption.
0078  *
0079  * It can be assumed that the executing thread locked the allocator mutex.
0080  * The only exception is the creation of the idle thread.  In this case the
0081  * allocator mutex is not locked.  Since the allocator mutex allows nesting the
0082  * normal memory allocation routines can be used.
0083  *
0084  * @param[in] executing The executing thread.
0085  * @param[in] created The created thread.
0086  *
0087  * @retval true Successful operation.
0088  * @retval false A thread create user extension will frequently attempt to
0089  * allocate resources.  If this allocation fails, then the extension should
0090  * return @a false and the entire thread create operation will fail.
0091  */
0092 typedef bool ( *User_extensions_thread_create_extension )(
0093   struct _Thread_Control *executing,
0094   struct _Thread_Control *created
0095 );
0096 
0097 /**
0098  * @brief Task delete extension.
0099  *
0100  * It corresponds to _Thread_Close() (used by the rtems_task_delete()
0101  * directive, pthread_exit() and pthread_cancel()).
0102  *
0103  * It is invoked before all resources of the thread are deleted.  The executing
0104  * and deleted arguments are never equal.
0105  *
0106  * Thread dispatching is enabled.  The executing thread locked the allocator
0107  * mutex.
0108  *
0109  * @param[in] executing The executing thread.
0110  * @param[in] deleted The deleted thread.
0111  */
0112 typedef void( *User_extensions_thread_delete_extension )(
0113   struct _Thread_Control *executing,
0114   struct _Thread_Control *deleted
0115 );
0116 
0117 /**
0118  * @brief Task start extension.
0119  *
0120  * It corresponds to _Thread_Start() (used by the rtems_task_start()
0121  * directive).
0122  *
0123  * It is invoked after the environment of the thread has been loaded and the
0124  * thread has been made ready.
0125  *
0126  * Thread dispatching is disabled.  The executing thread is not the holder of
0127  * the allocator mutex.
0128  *
0129  * @param[in] executing The executing thread.
0130  * @param[in] started The started thread.
0131  */
0132 typedef void( *User_extensions_thread_start_extension )(
0133   struct _Thread_Control *executing,
0134   struct _Thread_Control *started
0135 );
0136 
0137 /**
0138  * @brief Task restart extension.
0139  *
0140  * It corresponds to _Thread_Restart() (used by the rtems_task_restart()
0141  * directive).
0142  *
0143  * It is invoked in the context of the restarted thread right before the
0144  * execution context is reloaded.  The executing and restarted arguments are
0145  * always equal.  The thread stack reflects the previous execution context.
0146  *
0147  * Thread dispatching is enabled.  The thread is not the holder of the
0148  * allocator mutex.  The thread life is protected.  Thread restart and delete
0149  * requests issued by restart extensions lead to recursion.
0150  *
0151  * @param[in] executing The executing thread.
0152  * @param[in] restarted The executing thread.  Yes, the executing thread.
0153  */
0154 typedef void( *User_extensions_thread_restart_extension )(
0155   struct _Thread_Control *executing,
0156   struct _Thread_Control *restarted
0157 );
0158 
0159 /**
0160  * @brief Task switch extension.
0161  *
0162  * It corresponds to _Thread_Dispatch().
0163  *
0164  * It is invoked before the context switch from the executing to the heir
0165  * thread.
0166  *
0167  * Thread dispatching is disabled.  The state of the allocator mutex is
0168  * arbitrary.  Interrupts are disabled and the per-CPU lock is acquired on SMP
0169  * configurations.
0170  *
0171  * The context switches initiated through _Thread_Start_multitasking() are not
0172  * covered by this extension.
0173  *
0174  * @param[in] executing The executing thread.
0175  * @param[in] heir The heir thread.
0176  */
0177 typedef void( *User_extensions_thread_switch_extension )(
0178   struct _Thread_Control *executing,
0179   struct _Thread_Control *heir
0180 );
0181 
0182 /**
0183  * @brief Task begin extension.
0184  *
0185  * It corresponds to _Thread_Handler().
0186  *
0187  * Thread dispatching is disabled.  The executing thread is not the holder of
0188  * the allocator mutex.
0189  *
0190  * @param[in] executing The executing thread.
0191  */
0192 typedef void( *User_extensions_thread_begin_extension )(
0193   struct _Thread_Control *executing
0194 );
0195 
0196 /**
0197  * @brief Task exitted extension.
0198  *
0199  * It corresponds to _Thread_Handler() after a return of the entry function.
0200  *
0201  * Thread dispatching is disabled.  The state of the allocator mutex is
0202  * arbitrary.
0203  *
0204  * @param[in] executing The executing thread.
0205  */
0206 typedef void( *User_extensions_thread_exitted_extension )(
0207   struct _Thread_Control *executing
0208 );
0209 
0210 /**
0211  * @brief Fatal error extension.
0212  *
0213  * It corresponds to _Terminate() (used by the rtems_fatal() directive).
0214  *
0215  * This extension should not call any RTEMS directives.
0216  *
0217  * @param[in] source The fatal source indicating the subsystem the fatal
0218  * condition originated in.
0219  * @param[in] always_set_to_false This parameter is always set to false and
0220  * provided only for backward compatibility reasons.
0221  * @param[in] code The fatal error code.  This value must be interpreted with
0222  * respect to the source.
0223  */
0224 typedef void( *User_extensions_fatal_extension )(
0225   Internal_errors_Source source,
0226   bool                   always_set_to_false,
0227   Internal_errors_t      code
0228 );
0229 
0230 /**
0231  * @brief Task termination extension.
0232  *
0233  * This extension is invoked by _Thread_Life_action_handler() in case a
0234  * termination request is recognized.
0235  *
0236  * It is invoked in the context of the terminated thread right before the
0237  * thread dispatch to the heir thread.  The POSIX cleanup and key destructors
0238  * execute in this context.
0239  *
0240  * Thread dispatching is enabled.  The thread is not the holder of the
0241  * allocator mutex.  The thread life is protected.  Thread restart and delete
0242  * requests issued by terminate extensions lead to recursion.
0243  *
0244  * @param[in] terminated The terminated thread.
0245  */
0246 typedef void( *User_extensions_thread_terminate_extension )(
0247   struct _Thread_Control *terminated
0248 );
0249 
0250 /**
0251  * @brief User extension table.
0252  */
0253 typedef struct {
0254   User_extensions_thread_create_extension  thread_create;
0255   User_extensions_thread_start_extension   thread_start;
0256   User_extensions_thread_restart_extension thread_restart;
0257   User_extensions_thread_delete_extension  thread_delete;
0258   User_extensions_thread_switch_extension  thread_switch;
0259   User_extensions_thread_begin_extension   thread_begin;
0260   User_extensions_thread_exitted_extension thread_exitted;
0261   User_extensions_fatal_extension          fatal;
0262   User_extensions_thread_terminate_extension thread_terminate;
0263 }   User_extensions_Table;
0264 
0265 /** @} */
0266 
0267 #ifdef __cplusplus
0268 }
0269 #endif
0270 
0271 #endif
0272 /* end of include file */