@@ -73,6 +73,7 @@ static void async_context_task(__unused void *vself) {
73
73
async_context_freertos_release_lock (& self -> core );
74
74
__sev (); // it is possible regular code is waiting on a WFE on the other core
75
75
} while (!self -> task_should_exit );
76
+ xSemaphoreGive (self -> task_complete_sem );
76
77
vTaskDelete (NULL );
77
78
}
78
79
@@ -113,6 +114,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f
113
114
assert (config -> task_stack );
114
115
self -> lock_mutex = xSemaphoreCreateRecursiveMutexStatic (& self -> lock_mutex_buf );
115
116
self -> work_needed_sem = xSemaphoreCreateBinaryStatic (& self -> work_needed_sem_buf );
117
+ self -> task_complete_sem = xSemaphoreCreateBinaryStatic (& self -> task_complete_sem_buf );
116
118
self -> timer_handle = xTimerCreateStatic ( "async_context_timer" , // Just a text name, not used by the kernel.
117
119
portMAX_DELAY ,
118
120
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
129
131
#else
130
132
self -> lock_mutex = xSemaphoreCreateRecursiveMutex ();
131
133
self -> work_needed_sem = xSemaphoreCreateBinary ();
134
+ self -> task_complete_sem = xSemaphoreCreateBinary ();
132
135
self -> timer_handle = xTimerCreate ( "async_context_timer" , // Just a text name, not used by the kernel.
133
136
portMAX_DELAY ,
134
137
pdFALSE , // The timers will auto-reload themselves when they expire.
@@ -171,6 +174,9 @@ void async_context_freertos_deinit(async_context_t *self_base) {
171
174
async_context_freertos_t * self = (async_context_freertos_t * )self_base ;
172
175
if (self -> task_handle ) {
173
176
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
+ }
174
180
}
175
181
if (self -> timer_handle ) {
176
182
xTimerDelete (self -> timer_handle , 0 );
@@ -181,6 +187,9 @@ void async_context_freertos_deinit(async_context_t *self_base) {
181
187
if (self -> work_needed_sem ) {
182
188
vSemaphoreDelete (self -> work_needed_sem );
183
189
}
190
+ if (self -> task_complete_sem ) {
191
+ vSemaphoreDelete (self -> task_complete_sem );
192
+ }
184
193
memset (self , 0 , sizeof (* self ));
185
194
}
186
195
0 commit comments