Changeset e5ae7c92 in rtems


Ignore:
Timestamp:
Nov 7, 2012, 9:11:17 AM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
466cf31
Parents:
9ed2bef
git-author:
Sebastian Huber <sebastian.huber@…> (11/07/12 09:11:17)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/13/12 08:20:57)
Message:

score: Add and use _User_extensions_Iterate()

Replace the separate user extension iterations with a single iteration
function. This reduces code size and improves maintainability since the
iteration logic is only in one function. The runtime overhead is
insignificant.

Location:
cpukit/score
Files:
1 added
5 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/Makefile.am

    r9ed2bef re5ae7c92  
    319319## USEREXT_C_FILES
    320320libscore_a_SOURCES += src/userextaddset.c \
    321     src/userext.c src/userextremoveset.c src/userextthreadbegin.c \
    322     src/userextthreadcreate.c src/userextthreaddelete.c \
    323     src/userextthreadrestart.c src/userextthreadstart.c \
     321    src/userext.c src/userextremoveset.c src/userextiterate.c \
    324322    src/userextthreadswitch.c
    325323
  • cpukit/score/include/rtems/score/userext.h

    r9ed2bef re5ae7c92  
    275275);
    276276
     277/**
     278 * @brief User extension visitor.
     279 *
     280 * @param[in, out] executing The currently executing thread.
     281 * @param[in, out] arg The argument passed to _User_extensions_Iterate().
     282 * @param[in] callouts The current callouts.
     283 */
     284typedef void (*User_extensions_Visitor)(
     285  Thread_Control              *executing,
     286  void                        *arg,
     287  const User_extensions_Table *callouts
     288);
     289
     290typedef struct {
     291  Thread_Control *created;
     292  bool            ok;
     293} User_extensions_Thread_create_context;
     294
     295void _User_extensions_Thread_create_visitor(
     296  Thread_Control              *executing,
     297  void                        *arg,
     298  const User_extensions_Table *callouts
     299);
     300
     301void _User_extensions_Thread_delete_visitor(
     302  Thread_Control              *executing,
     303  void                        *arg,
     304  const User_extensions_Table *callouts
     305);
     306
     307void _User_extensions_Thread_start_visitor(
     308  Thread_Control              *executing,
     309  void                        *arg,
     310  const User_extensions_Table *callouts
     311);
     312
     313void _User_extensions_Thread_restart_visitor(
     314  Thread_Control              *executing,
     315  void                        *arg,
     316  const User_extensions_Table *callouts
     317);
     318
     319void _User_extensions_Thread_begin_visitor(
     320  Thread_Control              *executing,
     321  void                        *arg,
     322  const User_extensions_Table *callouts
     323);
     324
     325void _User_extensions_Thread_exitted_visitor(
     326  Thread_Control              *executing,
     327  void                        *arg,
     328  const User_extensions_Table *callouts
     329);
     330
     331typedef struct {
     332  Internal_errors_Source source;
     333  bool                   is_internal;
     334  Internal_errors_t      error;
     335} User_extensions_Fatal_context;
     336
     337void _User_extensions_Fatal_visitor(
     338  Thread_Control              *executing,
     339  void                        *arg,
     340  const User_extensions_Table *callouts
     341);
     342
     343/**
     344 * @brief Iterates through all user extensions and calls the visitor for each.
     345 *
     346 * @param[in, out] arg The argument passed to the visitor.
     347 * @param[in] visitor The visitor for each extension.
     348 */
     349void _User_extensions_Iterate(
     350  void                    *arg,
     351  User_extensions_Visitor  visitor
     352);
     353
    277354/** @} */
    278355
     
    283360 */
    284361
    285 bool _User_extensions_Thread_create(
    286   Thread_Control *created
    287 );
    288 
    289 void _User_extensions_Thread_delete(
    290   Thread_Control *deleted
    291 );
    292 
    293 void _User_extensions_Thread_start(
    294   Thread_Control *started
    295 );
    296 
    297 void _User_extensions_Thread_restart(
    298   Thread_Control *restarted
    299 );
    300 
    301 void _User_extensions_Thread_begin(
    302   Thread_Control *executing
    303 );
     362static inline bool _User_extensions_Thread_create( Thread_Control *created )
     363{
     364  User_extensions_Thread_create_context ctx = { created, true };
     365
     366  _User_extensions_Iterate( &ctx, _User_extensions_Thread_create_visitor );
     367
     368  return ctx.ok;
     369}
     370
     371static inline void _User_extensions_Thread_delete( Thread_Control *deleted )
     372{
     373  _User_extensions_Iterate(
     374    deleted,
     375    _User_extensions_Thread_delete_visitor
     376  );
     377}
     378
     379static inline void _User_extensions_Thread_start( Thread_Control *started )
     380{
     381  _User_extensions_Iterate(
     382    started,
     383    _User_extensions_Thread_start_visitor
     384  );
     385}
     386
     387static inline void _User_extensions_Thread_restart( Thread_Control *restarted )
     388{
     389  _User_extensions_Iterate(
     390    restarted,
     391    _User_extensions_Thread_restart_visitor
     392  );
     393}
     394
     395static inline void _User_extensions_Thread_begin( Thread_Control *executing )
     396{
     397  _User_extensions_Iterate(
     398    executing,
     399    _User_extensions_Thread_begin_visitor
     400  );
     401}
    304402
    305403void _User_extensions_Thread_switch(
     
    308406);
    309407
    310 void _User_extensions_Thread_exitted(
    311   Thread_Control *executing
    312 );
    313 
    314 void _User_extensions_Fatal(
     408static inline void _User_extensions_Thread_exitted( Thread_Control *executing )
     409{
     410  _User_extensions_Iterate(
     411    executing,
     412    _User_extensions_Thread_exitted_visitor
     413  );
     414}
     415
     416static inline void _User_extensions_Fatal(
    315417  Internal_errors_Source source,
    316418  bool                   is_internal,
    317419  Internal_errors_t      error
    318 );
     420)
     421{
     422  User_extensions_Fatal_context ctx = { source, is_internal, error };
     423
     424  _User_extensions_Iterate( &ctx, _User_extensions_Fatal_visitor );
     425}
    319426
    320427/** @} */
Note: See TracChangeset for help on using the changeset viewer.