-
Notifications
You must be signed in to change notification settings - Fork 1.1k
async_context_freertos: Add support for configSUPPORT_STATIC_ALLOCATION #2436
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
base: develop
Are you sure you want to change the base?
Conversation
The implementation of async_context_freertos currently assumes that FreeRTOS has been configured with `configSUPPORT_DYNAMIC_ALLOCATION`, which causes it to allocate semaphores, timers and tasks from the heap. However, some projects may prefer `configSUPPORT_STATIC_ALLOCATION`, which requires memory to be allocated ahead of time. This change allows async_context_freertos to support either static or dynamic allocation. The way this works is when `configSUPPORT_STATIC_ALLOCATION` is enabled, `async_context_freertos` struct will reserve extra space for the static objects (e.g. `StaticSemaphore_t`) and it will prefer to use the static creation functions (e.g. `xSemaphoreCreateBinaryStatic()`). For the task creation, the user will be responsible for allocating the stack memory and passing it in through the config. If a stack is not provided, then it will fallback to using dynamic allocation for the stack (e.g. `xTaskCreate()`).
|
||
if (!self->lock_mutex || | ||
!self->work_needed_sem || | ||
!self->timer_handle || | ||
pdPASS != xTaskCreate(async_context_task, "async_context_task", config->task_stack_size, self, | ||
config->task_priority, &self->task_handle)) { | ||
!(self->task_handle || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was trying to do here is make it so that if someone has both configSUPPORT_STATIC_ALLOCATION
and configSUPPORT_DYNAMIC_ALLOCATION
enabled, and they don't provide a task_stack
, then it will fallback to using xTaskCreate()
. I'm open to suggestions on making this cleaner.
@@ -68,9 +76,21 @@ typedef struct async_context_freertos_config { | |||
struct async_context_freertos { | |||
async_context_t core; | |||
SemaphoreHandle_t lock_mutex; | |||
#if configSUPPORT_STATIC_ALLOCATION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for style; i think i'd put all the _bufs
in a single #ifdef after the handles (I donl think there is any particular code size reason for them being close together)
The implementation of async_context_freertos currently assumes that FreeRTOS has been configured with
configSUPPORT_DYNAMIC_ALLOCATION
, which causes it to allocate semaphores, timers and tasks from the heap. However, some projects may preferconfigSUPPORT_STATIC_ALLOCATION
, which requires memory to be allocated ahead of time. This change allows async_context_freertos to support either static or dynamic allocation.The way this works is when
configSUPPORT_STATIC_ALLOCATION
is enabled,async_context_freertos
struct will reserve extra space for the static objects (e.g.StaticSemaphore_t
) and it will prefer to use the static creation functions (e.g.xSemaphoreCreateBinaryStatic()
). For the task creation, the user will be responsible for allocating the stack memory and passing it in through the config. If a stack is not provided, then it will fallback to using dynamic allocation for the stack (e.g.xTaskCreate()
).