@@ -73,6 +73,7 @@ static void async_context_task(__unused void *vself) {
7373 async_context_freertos_release_lock (& self -> core );
7474 __sev (); // it is possible regular code is waiting on a WFE on the other core
7575 } while (!self -> task_should_exit );
76+ xSemaphoreGive (self -> task_complete_sem );
7677 vTaskDelete (NULL );
7778}
7879
@@ -113,6 +114,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f
113114 assert (config -> task_stack );
114115 self -> lock_mutex = xSemaphoreCreateRecursiveMutexStatic (& self -> lock_mutex_buf );
115116 self -> work_needed_sem = xSemaphoreCreateBinaryStatic (& self -> work_needed_sem_buf );
117+ self -> task_complete_sem = xSemaphoreCreateBinaryStatic (& self -> task_complete_sem_buf );
116118 self -> timer_handle = xTimerCreateStatic ( "async_context_timer" , // Just a text name, not used by the kernel.
117119 portMAX_DELAY ,
118120 pdFALSE , // The timers will auto-reload themselves when they expire.
@@ -129,6 +131,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f
129131#else
130132 self -> lock_mutex = xSemaphoreCreateRecursiveMutex ();
131133 self -> work_needed_sem = xSemaphoreCreateBinary ();
134+ self -> task_complete_sem = xSemaphoreCreateBinary ();
132135 self -> timer_handle = xTimerCreate ( "async_context_timer" , // Just a text name, not used by the kernel.
133136 portMAX_DELAY ,
134137 pdFALSE , // The timers will auto-reload themselves when they expire.
@@ -171,6 +174,9 @@ void async_context_freertos_deinit(async_context_t *self_base) {
171174 async_context_freertos_t * self = (async_context_freertos_t * )self_base ;
172175 if (self -> task_handle ) {
173176 async_context_execute_sync (self_base , end_task_func , self_base );
177+ if (self -> task_complete_sem ) {
178+ xSemaphoreTake (self -> task_complete_sem , portMAX_DELAY );
179+ }
174180 }
175181 if (self -> timer_handle ) {
176182 xTimerDelete (self -> timer_handle , 0 );
@@ -181,6 +187,9 @@ void async_context_freertos_deinit(async_context_t *self_base) {
181187 if (self -> work_needed_sem ) {
182188 vSemaphoreDelete (self -> work_needed_sem );
183189 }
190+ if (self -> task_complete_sem ) {
191+ vSemaphoreDelete (self -> task_complete_sem );
192+ }
184193 memset (self , 0 , sizeof (* self ));
185194}
186195
0 commit comments