@@ -619,15 +619,45 @@ typedef void (*k_thread_user_cb_t)(const struct k_thread *thread,
619
619
* @param user_data Pointer to user data.
620
620
*
621
621
* @note CONFIG_THREAD_MONITOR must be set for this function
622
- * to be effective. Also this API uses irq_lock to protect the
623
- * _kernel.threads list which means creation of new threads and
624
- * terminations of existing threads are blocked until this
625
- * API returns.
622
+ * to be effective.
623
+ * @note This API uses @ref k_spin_lock to protect the _kernel.threads
624
+ * list which means creation of new threads and terminations of existing
625
+ * threads are blocked until this API returns.
626
626
*
627
627
* @return N/A
628
628
*/
629
629
extern void k_thread_foreach (k_thread_user_cb_t user_cb , void * user_data );
630
630
631
+ /**
632
+ * @brief Iterate over all the threads in the system without locking.
633
+ *
634
+ * This routine works exactly the same like @ref k_thread_foreach
635
+ * but unlocks interrupts when user_cb is executed.
636
+ *
637
+ * @param user_cb Pointer to the user callback function.
638
+ * @param user_data Pointer to user data.
639
+ *
640
+ * @note CONFIG_THREAD_MONITOR must be set for this function
641
+ * to be effective.
642
+ * @note This API uses @ref k_spin_lock only when accessing the _kernel.threads
643
+ * queue elements. It unlocks it during user callback function processing.
644
+ * If a new task is created when this @c foreach function is in progress,
645
+ * the added new task would not be included in the enumeration.
646
+ * If a task is aborted during this enumeration, there would be a race here
647
+ * and there is a possibility that this aborted task would be included in the
648
+ * enumeration.
649
+ * @note If the task is aborted and the memory occupied by its @c k_thread
650
+ * structure is reused when this @c k_thread_foreach_unlocked is in progress
651
+ * it might even lead to the system behave unstable.
652
+ * This function may never return, as it would follow some @c next task
653
+ * pointers treating given pointer as a pointer to the k_thread structure
654
+ * while it is something different right now.
655
+ * Do not reuse the memory that was occupied by k_thread structure of aborted
656
+ * task if it was aborted after this function was called in any context.
657
+ */
658
+ extern void k_thread_foreach_unlocked (
659
+ k_thread_user_cb_t user_cb , void * user_data );
660
+
631
661
/** @} */
632
662
633
663
/**
0 commit comments