[PATCH 2/5] score: Add API extensions post switch list
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Dec 3 11:54:08 UTC 2012
Move post switch hook from API_extensions_Control to new
API_extensions_Post_switch_control. Rename
_API_extensions_Run_postswitch() in _API_extensions_Run_post_switch().
Add _API_extensions_Post_switch_list and
_API_extensions_Add_post_switch().
---
cpukit/posix/src/pthread.c | 11 +++--
cpukit/rtems/src/tasks.c | 11 +++--
cpukit/score/include/rtems/score/apiext.h | 62 ++++++++++++++++++++++-------
cpukit/score/src/apiext.c | 1 +
cpukit/score/src/threaddispatch.c | 4 +-
5 files changed, 64 insertions(+), 25 deletions(-)
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index cd2cffe..e6f9289 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -305,12 +305,14 @@ static void _POSIX_Threads_Initialize_user_threads( void )
* API Extension control structures
*/
API_extensions_Control _POSIX_Threads_API_extensions = {
- { NULL, NULL },
#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
- NULL, /* predriver */
+ .predriver_hook = NULL,
#endif
- _POSIX_Threads_Initialize_user_threads, /* postdriver */
- _POSIX_signals_Post_switch_extension, /* post switch */
+ .postdriver_hook = _POSIX_Threads_Initialize_user_threads
+};
+
+API_extensions_Post_switch_control _POSIX_Threads_API_extensions_post_switch = {
+ .hook = _POSIX_signals_Post_switch_extension
};
User_extensions_Control _POSIX_Threads_User_extensions = {
@@ -357,6 +359,7 @@ void _POSIX_Threads_Manager_initialization(void)
_User_extensions_Add_API_set( &_POSIX_Threads_User_extensions );
_API_extensions_Add( &_POSIX_Threads_API_extensions );
+ _API_extensions_Add_post_switch( &_POSIX_Threads_API_extensions_post_switch );
/*
* If we supported MP, then here we would ...
diff --git a/cpukit/rtems/src/tasks.c b/cpukit/rtems/src/tasks.c
index 4164afe..36142d5 100644
--- a/cpukit/rtems/src/tasks.c
+++ b/cpukit/rtems/src/tasks.c
@@ -208,12 +208,14 @@ static void _RTEMS_tasks_Post_switch_extension(
}
API_extensions_Control _RTEMS_tasks_API_extensions = {
- { NULL, NULL },
#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
- NULL, /* predriver */
+ .predriver_hook = NULL,
#endif
- _RTEMS_tasks_Initialize_user_tasks, /* postdriver */
- _RTEMS_tasks_Post_switch_extension /* post switch */
+ .postdriver_hook = _RTEMS_tasks_Initialize_user_tasks
+};
+
+API_extensions_Post_switch_control _RTEMS_tasks_API_extensions_post_switch = {
+ .hook = _RTEMS_tasks_Post_switch_extension
};
User_extensions_Control _RTEMS_tasks_User_extensions = {
@@ -265,6 +267,7 @@ void _RTEMS_tasks_Manager_initialization(void)
_User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
_API_extensions_Add( &_RTEMS_tasks_API_extensions );
+ _API_extensions_Add_post_switch( &_RTEMS_tasks_API_extensions_post_switch );
/*
* Register the MP Process Packet routine.
diff --git a/cpukit/score/include/rtems/score/apiext.h b/cpukit/score/include/rtems/score/apiext.h
index afd828c..a44eacf 100644
--- a/cpukit/score/include/rtems/score/apiext.h
+++ b/cpukit/score/include/rtems/score/apiext.h
@@ -46,9 +46,9 @@
typedef void (*API_extensions_Postdriver_hook)(void);
/**
- * This type defines the prototype of the Postswitch Hook.
+ * This type defines the prototype of the Post Switch Hook.
*/
-typedef void (*API_extensions_Postswitch_hook)(
+typedef void (*API_extensions_Post_switch_hook)(
Thread_Control *
);
@@ -77,20 +77,34 @@ typedef struct {
* @note If this field is NULL, no extension is invoked.
*/
API_extensions_Postdriver_hook postdriver_hook;
+} API_extensions_Control;
+
+/**
+ * @brief Control structure for post switch hooks.
+ */
+typedef struct {
+ Chain_Node Node;
+
/**
- * This field is the callout invoked during each context switch
- * in the context of the heir thread.
+ * @brief The hook invoked during each context switch in the context of the
+ * heir thread.
*
- * @note If this field is NULL, no extension is invoked.
+ * This hook must not be NULL.
*/
- API_extensions_Postswitch_hook postswitch_hook;
-} API_extensions_Control;
+ API_extensions_Post_switch_hook hook;
+} API_extensions_Post_switch_control;
/**
* This is the list of API extensions to the system initialization.
*/
SCORE_EXTERN Chain_Control _API_extensions_List;
+
+/**
+ * @brief The API extensions post switch list.
+ */
+SCORE_EXTERN Chain_Control _API_extensions_Post_switch_list;
+
/**
* @brief Initialize the API Extensions Handler
*
@@ -109,6 +123,26 @@ void _API_extensions_Add(
API_extensions_Control *the_extension
);
+/**
+ * @brief Adds the API extension post switch control to the post switch list.
+ *
+ * The post switch control is only added to the list if it is in the off chain
+ * state. Thus this function can be called multiple times with the same
+ * post switch control and only the first invocation will actually add it to the
+ * list.
+ *
+ * @param [in] post_switch The post switch control.
+ */
+static inline void _API_extensions_Add_post_switch(
+ API_extensions_Post_switch_control *post_switch
+)
+{
+ _Chain_Append_if_node_is_off_chain(
+ &_API_extensions_Post_switch_list,
+ &post_switch->Node
+ );
+}
+
#if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
/**
* @brief Execute all Pre-Driver Extensions
@@ -126,21 +160,19 @@ void _API_extensions_Add(
void _API_extensions_Run_postdriver( void );
/**
- * @brief Execute all Post Context Switch Extensions
- *
- * This routine executes all of the post context switch callouts.
+ * @brief Runs all API extension post switch hooks.
*/
-static inline void _API_extensions_Run_postswitch( Thread_Control *executing )
+static inline void _API_extensions_Run_post_switch( Thread_Control *executing )
{
- const Chain_Control *chain = &_API_extensions_List;
+ const Chain_Control *chain = &_API_extensions_Post_switch_list;
const Chain_Node *tail = _Chain_Immutable_tail( chain );
const Chain_Node *node = _Chain_Immutable_first( chain );
while ( node != tail ) {
- const API_extensions_Control *extension =
- (const API_extensions_Control *) node;
+ const API_extensions_Post_switch_control *post_switch =
+ (const API_extensions_Post_switch_control *) node;
- (*extension->postswitch_hook)( executing );
+ (*post_switch->hook)( executing );
node = _Chain_Immutable_next( node );
}
diff --git a/cpukit/score/src/apiext.c b/cpukit/score/src/apiext.c
index b2ca87c..99965da 100644
--- a/cpukit/score/src/apiext.c
+++ b/cpukit/score/src/apiext.c
@@ -24,6 +24,7 @@
void _API_extensions_Initialization( void )
{
_Chain_Initialize_empty( &_API_extensions_List );
+ _Chain_Initialize_empty( &_API_extensions_Post_switch_list );
}
/*
diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c
index 283d278..66c7bdc 100644
--- a/cpukit/score/src/threaddispatch.c
+++ b/cpukit/score/src/threaddispatch.c
@@ -69,7 +69,7 @@ void _Thread_Dispatch( void )
*
* _Thread_Unnest_dispatch();
*
- * _API_extensions_Run_postswitch();
+ * _API_extensions_Run_post_switch();
* }
*
* The interrupt event makes task H ready. The interrupt code will see
@@ -202,5 +202,5 @@ post_switch:
_Thread_Unnest_dispatch();
#endif
- _API_extensions_Run_postswitch( executing );
+ _API_extensions_Run_post_switch( executing );
}
--
1.7.7
More information about the devel
mailing list