| 52 | } |
| 53 | |
| 54 | static void thread_main_body(void* context) { |
| 55 | check(context != nullptr); |
| 56 | auto* thread = static_cast<Thread*>(context); |
| 57 | |
| 58 | // Save Thread instance pointer to task local storage |
| 59 | check(pvTaskGetThreadLocalStoragePointer(nullptr, LOCAL_STORAGE_SELF_POINTER_INDEX) == nullptr); |
| 60 | vTaskSetThreadLocalStoragePointer(nullptr, LOCAL_STORAGE_SELF_POINTER_INDEX, thread); |
| 61 | |
| 62 | LOG_I(TAG, "Starting %s", thread->name.c_str()); // No need to lock as we don't allow mutation after thread start |
| 63 | check(thread->state == THREAD_STATE_STARTING); |
| 64 | thread_set_state_internal(thread, THREAD_STATE_RUNNING); |
| 65 | |
| 66 | int32_t result = thread->mainFunction(thread->mainFunctionContext); |
| 67 | thread->lock(); |
| 68 | thread->callbackResult = result; |
| 69 | thread->unlock(); |
| 70 | |
| 71 | check(thread->state == THREAD_STATE_RUNNING); |
| 72 | thread_set_state_internal(thread, THREAD_STATE_STOPPED); |
| 73 | LOG_I(TAG, "Stopped %s", thread->name.c_str()); // No need to lock as we don't allow mutation after thread start |
| 74 | |
| 75 | vTaskSetThreadLocalStoragePointer(nullptr, LOCAL_STORAGE_SELF_POINTER_INDEX, nullptr); |
| 76 | |
| 77 | thread->lock(); |
| 78 | thread->taskHandle = nullptr; |
| 79 | thread->unlock(); |
| 80 | |
| 81 | vTaskDelete(nullptr); |
| 82 | } |
| 83 | |
| 84 | extern "C" { |
| 85 |
nothing calls this directly
no test coverage detected