Repository: raspberrypi/pico-sdk
File: src/rp2_common/pico_async_context/async_context_freertos.c (C)

Code before:
                                             timer_handler,
                                             &self->timer_buf);

    if (config->task_stack) {
        self->task_handle = xTaskCreateStatic( async_context_task,
                                               "async_context_task",
                                               config->task_stack_size,
                                               self,
                                               config->task_priority,
                                               config->task_stack,
                                               &self->task_buf);
    }
#else
    self->lock_mutex = xSemaphoreCreateRecursiveMutex();
    self->work_needed_sem = xSemaphoreCreateBinary();
    self->timer_handle = xTimerCreate( "async_context_timer",       // Just a text name, not used by the kernel.
                                    portMAX_DELAY,
                                    pdFALSE,        // The timers will auto-reload themselves when they expire.
                                    self,
                                    timer_handler);
#endif

    if (!self->lock_mutex ||
        !self->work_needed_sem ||
        !self->timer_handle ||
        !(self->task_handle ||
#if configSUPPORT_DYNAMIC_ALLOCATION
          // Fallback to dynamic allocation for the task
          pdPASS == xTaskCreate(async_context_task, "async_context_task", config->task_stack_size, self,
              config->task_priority, &self->task_handle)
#else
          0
#endif
         )) {
        async_context_deinit(&self->core);
        return false;
    }
#if configNUMBER_OF_CORES > 1
    UBaseType_t core_id = config->task_core_id;
    if (core_id == (UBaseType_t)-1) {
        core_id = portGET_CORE_ID();
    }
    // we must run on a single core
    vTaskCoreAffinitySet(self->task_handle, 1u << core_id);
#endif
    return true;
}

static uint32_t end_task_func(void *param) {
    async_context_freertos_t *self = (async_context_freertos_t *)param;
    // we will immediately exit

Review comment (suggestion):
this seems a bit wordy.

Maybe just do 
```
     !self->timer_handle ||
#if configSUPPORT_STATIC_ALLOCATION
     !self->task_handle
#else
     pdPASS != xTaskCreate(async_context_task, "async_context_task", config->task_stack_size, self, ... )
#endif
```


Code after:
                                             self,
                                             timer_handler,
                                             &self->timer_buf);
    self->task_handle = xTaskCreateStatic( async_context_task,
                                           "async_context_task",
                                           config->task_stack_size,
                                           self,
                                           config->task_priority,
                                           config->task_stack,
                                           &self->task_buf);
#else
    self->lock_mutex = xSemaphoreCreateRecursiveMutex();
    self->work_needed_sem = xSemaphoreCreateBinary();
    self->timer_handle = xTimerCreate( "async_context_timer",       // Just a text name, not used by the kernel.
                                    portMAX_DELAY,
                                    pdFALSE,        // The timers will auto-reload themselves when they expire.
                                    self,
                                    timer_handler);
#endif

    if (!self->lock_mutex ||
        !self->work_needed_sem ||
        !self->timer_handle ||
#if configSUPPORT_STATIC_ALLOCATION
        !self->task_handle
#else
        pdPASS != xTaskCreate(async_context_task, "async_context_task", config->task_stack_size, self,
                config->task_priority, &self->task_handle)
#endif
    ) {
        async_context_deinit(&self->core);
        return false;
    }
#if configNUMBER_OF_CORES > 1
    UBaseType_t core_id = config->task_core_id;
    if (core_id == (UBaseType_t)-1) {
        core_id = portGET_CORE_ID();
    }
    // we must run on a single core
    vTaskCoreAffinitySet(self->task_handle, 1u << core_id);
#endif
    return true;
}

static uint32_t end_task_func(void *param) {
    async_context_freertos_t *self = (async_context_freertos_t *)param;
    // we will immediately exit
    self->task_should_exit = true;
    return 0;
}