From d271c3bb78f86dd9417a964b019b8e38911064fa Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 31 Oct 2016 13:37:59 +0100 Subject: rtems: Add rtems_task_iterate() Update #2423. --- cpukit/rtems/Makefile.am | 1 + cpukit/rtems/include/rtems/rtems/tasks.h | 32 ++++++++++++++++++++++++++++++++ cpukit/rtems/src/taskiterate.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 cpukit/rtems/src/taskiterate.c (limited to 'cpukit/rtems') diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am index 4be426620c..6ecff9e068 100644 --- a/cpukit/rtems/Makefile.am +++ b/cpukit/rtems/Makefile.am @@ -93,6 +93,7 @@ librtems_a_SOURCES += src/taskgetscheduler.c librtems_a_SOURCES += src/taskident.c librtems_a_SOURCES += src/taskinitusers.c librtems_a_SOURCES += src/taskissuspended.c +librtems_a_SOURCES += src/taskiterate.c librtems_a_SOURCES += src/taskmode.c librtems_a_SOURCES += src/taskrestart.c librtems_a_SOURCES += src/taskresume.c diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h index 0eaaeca4a3..180e50eed7 100644 --- a/cpukit/rtems/include/rtems/rtems/tasks.h +++ b/cpukit/rtems/include/rtems/rtems/tasks.h @@ -512,6 +512,38 @@ rtems_status_code rtems_task_set_scheduler( */ rtems_id rtems_task_self(void); +/** + * @brief Task visitor. + * + * @param[in] tcb The task control block. + * @param[in] arg The visitor argument. + * + * @retval true Stop the iteration. + * @retval false Otherwise. + * + * @see rtems_task_iterate(). + */ +typedef bool ( *rtems_task_visitor )( rtems_tcb *tcb, void *arg ); + +/** + * @brief Iterates over all tasks in the system. + * + * This operation covers all tasks of all APIs. + * + * Must be called from task context. This operation obtains and releases the + * objects allocator lock. The task visitor is called while owning the objects + * allocator lock. It is possible to perform blocking operations in the task + * visitor, however, take care that no deadlocks via the object allocator lock + * can occur. + * + * @param[in] visitor The task visitor. + * @param[in] arg The visitor argument. + */ +void rtems_task_iterate( + rtems_task_visitor visitor, + void *arg +); + /** * @brief Identifies a scheduler by its name. * diff --git a/cpukit/rtems/src/taskiterate.c b/cpukit/rtems/src/taskiterate.c new file mode 100644 index 0000000000..853551b599 --- /dev/null +++ b/cpukit/rtems/src/taskiterate.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include + +void rtems_task_iterate( + rtems_task_visitor visitor, + void *arg +) +{ + _Objects_Allocator_lock(); + _Thread_Iterate( visitor, arg ); + _Objects_Allocator_unlock(); +} -- cgit v1.2.3