@@ -176,10 +176,8 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
176176 pdata -> flat -> ret = - ENOSYS ;
177177
178178 ret = ipc_thread_flatten (cmd , param , pdata -> flat );
179- if (!ret ) {
180- pdata -> pend_ipc ++ ;
181- k_sem_give (pdata -> sem );
182- }
179+ if (!ret )
180+ k_event_post (pdata -> event , DP_TASK_EVENT_IPC );
183181
184182 scheduler_dp_unlock (lock_key );
185183
@@ -225,8 +223,7 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
225223 /* trigger the task */
226224 curr_task -> state = SOF_TASK_STATE_RUNNING ;
227225 trigger_task = true;
228- pdata -> pend_proc ++ ;
229- k_sem_give (pdata -> sem );
226+ k_event_post (pdata -> event , DP_TASK_EVENT_PROCESS );
230227 }
231228
232229 if (curr_task -> state == SOF_TASK_STATE_RUNNING ) {
@@ -278,41 +275,18 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
278275 comp_info (pmod -> dev , "userspace thread started" );
279276
280277 do {
281- /*
282- * The thread is started immediately after creation, it stops here and waits
283- * for the semaphore to be signalled to handle IPC or process audio data.
284- */
285- k_sem_take (task_pdata -> sem , K_FOREVER );
286-
287- lock_key = scheduler_dp_lock (task -> core );
288-
289- unsigned char pend_ipc = task_pdata -> pend_ipc ,
290- pend_proc = task_pdata -> pend_proc ;
291-
292- task_pdata -> pend_proc = 0 ;
293- task_pdata -> pend_ipc = 0 ;
294-
295- scheduler_dp_unlock (lock_key );
296-
297- /*
298- * Only 0:1, 1:0 and 1:1 are valid. 0:0 is also possible if IPC and audio
299- * were signalled in a quick succession before we took the lock above. Any
300- * value > 1 would mean that we've missed IPCs or LL ticks while in queued /
301- * idle state, which shouldn't happen.
302- */
303- if (pend_ipc > 1 || pend_proc > 1 ) {
304- tr_err (& dp_tr , "Invalid wake up %u:%u" , pend_proc , pend_ipc );
305- continue ;
306- }
278+ uint32_t mask = k_event_wait_safe (task_pdata -> event ,
279+ DP_TASK_EVENT_PROCESS | DP_TASK_EVENT_CANCEL |
280+ DP_TASK_EVENT_IPC , false, K_FOREVER );
307281
308- if (pend_ipc ) {
282+ if (mask & DP_TASK_EVENT_IPC ) {
309283 /* handle IPC */
310284 tr_dbg (& dp_tr , "got IPC wake up for %p state %d" , pmod , task -> state );
311285 ipc_thread_unflatten_run (pmod , task_pdata -> flat );
312286 k_sem_give (& dp_sync [task -> core ]);
313287 }
314288
315- if (pend_proc ) {
289+ if (mask & DP_TASK_EVENT_PROCESS ) {
316290 bool ready ;
317291
318292 if (task -> state == SOF_TASK_STATE_RUNNING ) {
@@ -459,8 +433,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
459433
460434 pdata -> flat = & task_memory -> flat ;
461435
462- pdata -> sem = k_object_alloc (K_OBJ_SEM );
463- if (!pdata -> sem ) {
436+ pdata -> event = k_object_alloc (K_OBJ_EVENT );
437+ if (!pdata -> event ) {
464438 tr_err (& dp_tr , "Event object allocation failed" );
465439 ret = - ENOMEM ;
466440 goto e_stack ;
@@ -497,7 +471,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
497471 goto e_thread ;
498472 }
499473
500- k_thread_access_grant (pdata -> thread_id , pdata -> sem , & dp_sync [core ]);
474+ k_thread_access_grant (pdata -> thread_id , pdata -> event , & dp_sync [core ]);
501475 scheduler_dp_grant (pdata -> thread_id , core );
502476
503477 unsigned int pidx ;
@@ -564,7 +538,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
564538 }
565539
566540 /* start the thread, it should immediately stop at the semaphore */
567- k_sem_init (pdata -> sem , 0 , 1 );
541+ k_event_init (pdata -> event );
568542 k_thread_start (pdata -> thread_id );
569543
570544 return 0 ;
@@ -576,7 +550,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
576550e_kobj :
577551 /* k_object_free looks for a pointer in the list, any invalid value can be passed */
578552 k_object_free (pdata -> thread );
579- k_object_free (pdata -> sem );
553+ k_object_free (pdata -> event );
580554e_stack :
581555 user_stack_free (p_stack );
582556e_tmem :
0 commit comments