| 51 | static_assert(static_cast<UBaseType_t>(Priority::Critical) < configMAX_PRIORITIES, "Highest thread priority is higher than max priority"); |
| 52 | |
| 53 | static void mainBody(void* context) { |
| 54 | assert(context != nullptr); |
| 55 | auto* thread = static_cast<Thread*>(context); |
| 56 | |
| 57 | // Save Thread instance pointer to task local storage |
| 58 | assert(pvTaskGetThreadLocalStoragePointer(nullptr, LOCAL_STORAGE_SELF_POINTER_INDEX) == nullptr); |
| 59 | vTaskSetThreadLocalStoragePointer(nullptr, LOCAL_STORAGE_SELF_POINTER_INDEX, thread); |
| 60 | |
| 61 | #ifdef ESP_PLATFORM |
| 62 | ESP_LOGI(TAG, "Starting %s", thread->name.c_str()); |
| 63 | #endif |
| 64 | assert(thread->state == State::Starting); |
| 65 | thread->setState(State::Running); |
| 66 | thread->callbackResult = thread->mainFunction(); |
| 67 | assert(thread->state == State::Running); |
| 68 | thread->setState(State::Stopped); |
| 69 | #ifdef ESP_PLATFORM |
| 70 | ESP_LOGI(TAG, "Stopped %s", thread->name.c_str()); |
| 71 | #endif |
| 72 | |
| 73 | vTaskSetThreadLocalStoragePointer(nullptr, 0, nullptr); |
| 74 | thread->taskHandle = nullptr; |
| 75 | |
| 76 | vTaskDelete(nullptr); |
| 77 | } |
| 78 | |
| 79 | TaskHandle_t taskHandle = nullptr; |
| 80 | State state = State::Stopped; |