Skip to content

Commit e676bf3

Browse files
utsavm9kartben
authored andcommitted
portability: cmsis: Store thread name within Zephyr k_thread
Use underlying Zephyr thread directly to store thread name instead of storing the name in CMSIS control block. Also, allow `osThreadGetName` to work within ISR, as expected from spec. Signed-off-by: Utsav Munendra <[email protected]>
1 parent 1ce32f0 commit e676bf3

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

include/zephyr/portability/cmsis_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct cmsis_rtos_thread_cb {
2626
struct k_poll_signal poll_signal;
2727
struct k_poll_event poll_event;
2828
uint32_t signal_results;
29-
char name[CMSIS_OBJ_NAME_MAX_LEN];
3029
uint32_t attr_bits;
3130
};
3231

subsys/portability/cmsis_rtos_v2/thread.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,37 +192,24 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, const osThreadAtt
192192
(void)k_thread_create(&tid->z_thread, stack, stack_size, zephyr_thread_wrapper, (void *)arg,
193193
NULL, threadfunc, prio, 0, K_NO_WAIT);
194194

195-
if (attr->name == NULL) {
196-
strncpy(tid->name, init_thread_attrs.name, sizeof(tid->name) - 1);
197-
} else {
198-
strncpy(tid->name, attr->name, sizeof(tid->name) - 1);
199-
}
200-
201-
k_thread_name_set(&tid->z_thread, tid->name);
195+
const char *name = (attr->name == NULL) ? init_thread_attrs.name : attr->name;
196+
k_thread_name_set(&tid->z_thread, name);
202197

203198
return (osThreadId_t)tid;
204199
}
205200

206201
/**
207202
* @brief Get name of a thread.
203+
* This function may be called from Interrupt Service Routines.
208204
*/
209205
const char *osThreadGetName(osThreadId_t thread_id)
210206
{
211-
const char *name = NULL;
212-
213-
if (k_is_in_isr() || (thread_id == NULL)) {
214-
name = NULL;
215-
} else {
216-
if (is_cmsis_rtos_v2_thread(thread_id) == NULL) {
217-
name = NULL;
218-
} else {
219-
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
207+
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
220208

221-
name = k_thread_name_get(&tid->z_thread);
222-
}
209+
if (tid == NULL) {
210+
return NULL;
223211
}
224-
225-
return name;
212+
return k_thread_name_get(&tid->z_thread);
226213
}
227214

228215
/**

0 commit comments

Comments
 (0)