RTX5: added function for thread enumeration
diff --git a/CMSIS/RTOS2/Include/cmsis_os2.h b/CMSIS/RTOS2/Include/cmsis_os2.h
index 57f0906..259dc0e 100644
--- a/CMSIS/RTOS2/Include/cmsis_os2.h
+++ b/CMSIS/RTOS2/Include/cmsis_os2.h
@@ -412,9 +412,9 @@
/// Enumerate active threads.
/// \param[out] thread_array pointer to array for retrieving thread IDs.
-/// \param[in] array_size size of array for retrieving thread IDs.
+/// \param[in] array_items maximum number of items in array for retrieving thread IDs.
/// \return number of enumerated threads.
-uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_size);
+uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
// ==== Thread Flags Functions ====
diff --git a/CMSIS/RTOS2/RTX/Include1/cmsis_os.h b/CMSIS/RTOS2/RTX/Include1/cmsis_os.h
index e3cbd09..216d1ef 100644
--- a/CMSIS/RTOS2/RTX/Include1/cmsis_os.h
+++ b/CMSIS/RTOS2/RTX/Include1/cmsis_os.h
@@ -66,6 +66,7 @@
* - added: osThreadGetStackSize, osThreadGetStackSpace
* - added: osThreadSuspend, osThreadResume
* - added: osThreadJoin, osThreadDetach, osThreadExit
+ * - added: osThreadGetCount, osThreadEnumerate
* - added: Thread Flags (moved from Signals)
* Signals:
* - renamed osSignals to osThreadFlags (moved to Thread Flags)
diff --git a/CMSIS/RTOS2/RTX/Source/rtx_lib.h b/CMSIS/RTOS2/RTX/Source/rtx_lib.h
index 7f60572..bf50711 100644
--- a/CMSIS/RTOS2/RTX/Source/rtx_lib.h
+++ b/CMSIS/RTOS2/RTX/Source/rtx_lib.h
@@ -126,6 +126,8 @@
extern osStatus_t os_svcThreadJoin (osThreadId_t thread_id);
extern void os_svcThreadExit (void);
extern osStatus_t os_svcThreadTerminate (osThreadId_t thread_id);
+extern uint32_t os_svcThreadGetCount (void);
+extern uint32_t os_svcThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
extern int32_t os_svcThreadFlagsSet (osThreadId_t thread_id, int32_t flags);
extern int32_t os_svcThreadFlagsClear (int32_t flags);
extern int32_t os_svcThreadFlagsGet (void);
diff --git a/CMSIS/RTOS2/RTX/Source/rtx_thread.c b/CMSIS/RTOS2/RTX/Source/rtx_thread.c
index ba0af65..fd181dc 100644
--- a/CMSIS/RTOS2/RTX/Source/rtx_thread.c
+++ b/CMSIS/RTOS2/RTX/Source/rtx_thread.c
@@ -518,6 +518,8 @@
SVC0_1 (ThreadJoin, osStatus_t, osThreadId_t)
SVC0_0N(ThreadExit, void)
SVC0_1 (ThreadTerminate, osStatus_t, osThreadId_t)
+SVC0_0 (ThreadGetCount, uint32_t)
+SVC0_2 (ThreadEnumerate, uint32_t, osThreadId_t *, uint32_t)
SVC0_2 (ThreadFlagsSet, int32_t, osThreadId_t, int32_t)
SVC0_1 (ThreadFlagsClear, int32_t, int32_t)
SVC0_0 (ThreadFlagsGet, int32_t)
@@ -1141,6 +1143,66 @@
return osOK;
}
+/// Get number of active threads.
+/// \note API identical to osThreadGetCount
+uint32_t os_svcThreadGetCount (void) {
+ os_thread_t *thread;
+ uint32_t count;
+
+ // Running Thread
+ count = 1U;
+
+ // Ready List
+ for (thread = os_Info.thread.ready.thread_list;
+ (thread != NULL); thread = thread->thread_next, count++);
+
+ // Delay List
+ for (thread = os_Info.thread.delay_list;
+ (thread != NULL); thread = thread->delay_next, count++);
+
+ // Wait List
+ for (thread = os_Info.thread.wait_list;
+ (thread != NULL); thread = thread->delay_next, count++);
+
+ return count;
+}
+
+/// Enumerate active threads.
+/// \note API identical to osThreadEnumerate
+uint32_t os_svcThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) {
+ os_thread_t *thread;
+ uint32_t count;
+
+ // Check parameters
+ if ((thread_array == NULL) || (array_items == 0U)) {
+ return 0U;
+ }
+
+ // Running Thread
+ *thread_array++ = os_ThreadGetRunning();
+ count = 1U;
+
+ // Ready List
+ for (thread = os_Info.thread.ready.thread_list;
+ (thread != NULL) && (count < array_items); thread = thread->thread_next, count++) {
+ *thread_array++ = thread;
+ }
+
+ // Delay List
+ for (thread = os_Info.thread.delay_list;
+ (thread != NULL) && (count < array_items); thread = thread->delay_next, count++) {
+ *thread_array++ = thread;
+ }
+
+ // Wait List
+ for (thread = os_Info.thread.wait_list;
+ (thread != NULL) && (count < array_items); thread = thread->delay_next, count++) {
+ *thread_array++ = thread;
+ }
+
+ return count;
+}
+
/// Set the specified Thread Flags of a thread.
/// \note API identical to osThreadFlagsSet
int32_t os_svcThreadFlagsSet (osThreadId_t thread_id, int32_t flags) {
@@ -1421,6 +1483,22 @@
return __svcThreadTerminate(thread_id);
}
+/// Get number of active threads.
+uint32_t osThreadGetCount (void) {
+ if (__get_IPSR() != 0U) {
+ return 0U; // Not allowed in ISR
+ }
+ return __svcThreadGetCount();
+}
+
+/// Enumerate active threads.
+uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) {
+ if (__get_IPSR() != 0U) {
+ return 0U; // Not allowed in ISR
+ }
+ return __svcThreadEnumerate(thread_array, array_items);
+}
+
/// Set the specified Thread Flags of a thread.
int32_t osThreadFlagsSet (osThreadId_t thread_id, int32_t flags) {
if (__get_IPSR() != 0U) { // in ISR