summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-10-31 13:37:59 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-11-02 08:46:47 +0100
commitd271c3bb78f86dd9417a964b019b8e38911064fa (patch)
tree3c36b87c580464cc7f1e5aec89e1137a68759da3 /cpukit/score
parentposix: Fix timer interval (diff)
downloadrtems-d271c3bb78f86dd9417a964b019b8e38911064fa.tar.bz2
rtems: Add rtems_task_iterate()
Update #2423.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/Makefile.am1
-rw-r--r--cpukit/score/include/rtems/score/thread.h10
-rw-r--r--cpukit/score/include/rtems/score/threadimpl.h7
-rw-r--r--cpukit/score/src/iterateoverthreads.c45
-rw-r--r--cpukit/score/src/threaditerate.c60
5 files changed, 88 insertions, 35 deletions
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index a196ff5dae..bb313a752d 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -310,6 +310,7 @@ libscore_a_SOURCES += src/threadentryadaptornumeric.c
libscore_a_SOURCES += src/threadentryadaptorpointer.c
libscore_a_SOURCES += src/threadgetcputimeused.c
libscore_a_SOURCES += src/threadglobalconstruction.c
+libscore_a_SOURCES += src/threaditerate.c
libscore_a_SOURCES += src/threadtimeout.c
libscore_a_SOURCES += src/threadwaitgetid.c
libscore_a_SOURCES += src/threadyield.c
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index a86d81b4e2..d839b1f9ec 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -834,18 +834,12 @@ void *_Thread_Idle_body(
);
#endif
-/** This defines the type for a method which operates on a single thread.
- */
typedef void (*rtems_per_thread_routine)( Thread_Control * );
-/**
- * @brief Iterates over all threads.
- * This routine iterates over all threads regardless of API and
- * invokes the specified routine.
- */
+/* Use rtems_task_iterate() instead */
void rtems_iterate_over_all_threads(
rtems_per_thread_routine routine
-);
+) RTEMS_DEPRECATED;
/**
* @brief Thread control add-on.
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 7b978ea477..51d9d473bf 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -83,6 +83,13 @@ extern Thread_Control *_Thread_Allocated_fp;
RTEMS_CONTAINER_OF( node, Thread_Control, Resource_node )
#endif
+typedef bool ( *Thread_Visitor )( Thread_Control *the_thread, void *arg );
+
+void _Thread_Iterate(
+ Thread_Visitor visitor,
+ void *arg
+);
+
void _Thread_Initialize_information(
Thread_Information *information,
Objects_APIs the_api,
diff --git a/cpukit/score/src/iterateoverthreads.c b/cpukit/score/src/iterateoverthreads.c
index 8933352298..e829fc9edb 100644
--- a/cpukit/score/src/iterateoverthreads.c
+++ b/cpukit/score/src/iterateoverthreads.c
@@ -18,37 +18,28 @@
#include "config.h"
#endif
-#include <rtems/score/thread.h>
-#include <rtems/score/objectimpl.h>
+#include <rtems/score/threadimpl.h>
-void rtems_iterate_over_all_threads(rtems_per_thread_routine routine)
-{
- uint32_t i;
- uint32_t api_index;
- Thread_Control *the_thread;
- Objects_Information *information;
-
- if ( !routine )
- return;
+typedef struct {
+ rtems_per_thread_routine routine;
+} routine_arg;
- for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
- #if !defined(RTEMS_POSIX_API) || defined(RTEMS_DEBUG)
- if ( !_Objects_Information_table[ api_index ] )
- continue;
- #endif
-
- information = _Objects_Information_table[ api_index ][ 1 ];
- if ( !information )
- continue;
+static bool routine_adaptor( rtems_tcb *tcb, void *arg )
+{
+ routine_arg *ra;
- for ( i=1 ; i <= information->maximum ; i++ ) {
- the_thread = (Thread_Control *)information->local_table[ i ];
+ ra = arg;
+ ( *ra->routine )( tcb );
+ return false;
+}
- if ( !the_thread )
- continue;
+void rtems_iterate_over_all_threads( rtems_per_thread_routine routine )
+{
+ routine_arg arg = {
+ .routine = routine
+ };
- (*routine)(the_thread);
- }
+ if ( routine != NULL ) {
+ _Thread_Iterate( routine_adaptor, &arg );
}
-
}
diff --git a/cpukit/score/src/threaditerate.c b/cpukit/score/src/threaditerate.c
new file mode 100644
index 0000000000..0f9a1bef44
--- /dev/null
+++ b/cpukit/score/src/threaditerate.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/score/threadimpl.h>
+
+void _Thread_Iterate(
+ Thread_Visitor visitor,
+ void *arg
+)
+{
+ int api_index;
+
+ for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; ++api_index ) {
+ const Objects_Information *information;
+ Objects_Maximum i;
+
+#if !defined(RTEMS_POSIX_API)
+ if ( _Objects_Information_table[ api_index ] == NULL ) {
+ continue;
+ }
+#endif
+
+ information = _Objects_Information_table[ api_index ][ 1 ];
+
+ if ( information == NULL ) {
+ continue;
+ }
+
+ for ( i = 1 ; i <= information->maximum ; ++i ) {
+ Thread_Control *the_thread;
+
+ the_thread = (Thread_Control *) information->local_table[ i ];
+
+ if ( the_thread != NULL ) {
+ bool done;
+
+ done = (* visitor )( the_thread, arg );
+
+ if ( done ) {
+ return;
+ }
+ }
+ }
+ }
+}