@@ -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 ) {
@@ -411,7 +385,7 @@ void scheduler_dp_internal_free(struct task *task)
411385{
412386 struct task_dp_pdata * pdata = task -> priv_data ;
413387
414- k_object_free (pdata -> sem );
388+ k_object_free (pdata -> event );
415389 k_object_free (pdata -> thread );
416390 scheduler_dp_domain_free (pdata );
417391
@@ -471,8 +445,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
471445
472446 pdata -> flat = & task_memory -> flat ;
473447
474- pdata -> sem = k_object_alloc (K_OBJ_SEM );
475- if (!pdata -> sem ) {
448+ pdata -> event = k_object_alloc (K_OBJ_EVENT );
449+ if (!pdata -> event ) {
476450 tr_err (& dp_tr , "Event object allocation failed" );
477451 ret = - ENOMEM ;
478452 goto e_stack ;
@@ -509,7 +483,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
509483 goto e_thread ;
510484 }
511485
512- k_thread_access_grant (pdata -> thread_id , pdata -> sem , & dp_sync [core ]);
486+ k_thread_access_grant (pdata -> thread_id , pdata -> event , & dp_sync [core ]);
513487 scheduler_dp_grant (pdata -> thread_id , core );
514488
515489 unsigned int pidx ;
@@ -579,7 +553,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
579553 }
580554
581555 /* start the thread, it should immediately stop at the semaphore */
582- k_sem_init (pdata -> sem , 0 , 1 );
556+ k_event_init (pdata -> event );
583557 k_thread_start (pdata -> thread_id );
584558
585559 return 0 ;
@@ -591,7 +565,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
591565e_kobj :
592566 /* k_object_free looks for a pointer in the list, any invalid value can be passed */
593567 k_object_free (pdata -> thread );
594- k_object_free (pdata -> sem );
568+ k_object_free (pdata -> event );
595569e_stack :
596570 user_stack_free (p_stack );
597571e_tmem :
0 commit comments