diff --git a/include/ableton/platforms/esp32/Context.hpp b/include/ableton/platforms/esp32/Context.hpp index e3a9040d..27fb8b52 100644 --- a/include/ableton/platforms/esp32/Context.hpp +++ b/include/ableton/platforms/esp32/Context.hpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -40,6 +39,10 @@ class Context { class ServiceRunner { + // This task used to exclusively poll ASIO with `poll_one()`, with an + // interval of 100 microseconds. Since ASIO uses `select()` internally to + // implement `poll_one()`, we might as well use an event based approach and + // save some CPU cycles by using `io_service::run()` instead. static void run(void* userParams) { auto runner = static_cast(userParams); @@ -47,8 +50,7 @@ class Context { try { - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - runner->mpService->poll_one(); + runner->mpService->run(); } catch (...) { @@ -56,16 +58,6 @@ class Context } } - static void IRAM_ATTR timerIsr(void* userParam) - { - static BaseType_t xHigherPriorityTaskWoken = pdFALSE; - vTaskNotifyGiveFromISR(*((TaskHandle_t*)userParam), &xHigherPriorityTaskWoken); - if (xHigherPriorityTaskWoken) - { - portYIELD_FROM_ISR(); - } - } - public: ServiceRunner() : mpService(new ::asio::io_service()) @@ -78,24 +70,9 @@ class Context 2 | portPRIVILEGE_BIT, &mTaskHandle, LINK_ESP_TASK_CORE_ID); - - const esp_timer_create_args_t timerArgs = { - .callback = &timerIsr, - .arg = (void*)&mTaskHandle, - .dispatch_method = ESP_TIMER_TASK, - .name = "link", - .skip_unhandled_events = true, - }; - - ESP_ERROR_CHECK(esp_timer_create(&timerArgs, &mTimer)); - ESP_ERROR_CHECK(esp_timer_start_periodic(mTimer, 100)); } - ~ServiceRunner() - { - esp_timer_delete(mTimer); - vTaskDelete(mTaskHandle); - } + ~ServiceRunner() { vTaskDelete(mTaskHandle); } template void async(Handler handler) @@ -107,7 +84,6 @@ class Context private: TaskHandle_t mTaskHandle; - esp_timer_handle_t mTimer; std::unique_ptr<::asio::io_service> mpService; std::unique_ptr<::asio::io_service::work> mpWork; };