Skip to content

Add thread terminate hook #4684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TESTS/mbedmicro-rtos-mbed/threads/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ void test_thread_prio() {
}

utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(15, "default_auto");
GREENTEA_SETUP(20, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
27 changes: 27 additions & 0 deletions rtos/TARGET_CORTEX/mbed_rtx_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
#include "rtx_evr.h"
#include "mbed_rtx.h"
#include "mbed_error.h"
#include "RTX_Config.h"

#ifdef RTE_Compiler_EventRecorder
#include "EventRecorder.h" // Keil::Compiler:Event Recorder
// Used from rtx_evr.c
#define EvtRtxThreadExit EventID(EventLevelAPI, 0xF2U, 0x19U)
#define EvtRtxThreadTerminate EventID(EventLevelAPI, 0xF2U, 0x1AU)
#endif

extern void rtos_idle_loop(void);
extern void thread_terminate_hook(osThreadId_t id);

__NO_RETURN void osRtxIdleThread (void *argument)
{
Expand Down Expand Up @@ -136,3 +145,21 @@ void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status)
}

#endif

// RTX hook which gets called when a thread terminates, using the event function to call hook
void EvrRtxThreadExit (void)
{
osThreadId_t thread_id = osThreadGetId();
thread_terminate_hook(thread_id);
#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_EXIT_DISABLE) && defined(RTE_Compiler_EventRecorder))
EventRecord2(EvtRtxThreadExit, 0U, 0U);
#endif
}

void EvrRtxThreadTerminate (osThreadId_t thread_id)
{
thread_terminate_hook(thread_id);
#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE) && defined(RTE_Compiler_EventRecorder))
EventRecord2(EvtRtxThreadTerminate, (uint32_t)thread_id, 0U);
#endif
}