@@ -175,10 +175,8 @@ int scheduler_dp_thread_ipc(struct processing_module *pmod, unsigned int cmd,
175175 pdata -> flat -> ret = - ENOSYS ;
176176
177177 ret = ipc_thread_flatten (cmd , param , pdata -> flat );
178- if (!ret ) {
179- pdata -> pend_ipc ++ ;
180- k_sem_give (pdata -> sem );
181- }
178+ if (!ret )
179+ k_event_post (pdata -> event , DP_TASK_EVENT_IPC );
182180
183181 scheduler_dp_unlock (lock_key );
184182
@@ -224,8 +222,7 @@ void scheduler_dp_recalculate(struct scheduler_dp_data *dp_sch, bool is_ll_post_
224222 /* trigger the task */
225223 curr_task -> state = SOF_TASK_STATE_RUNNING ;
226224 trigger_task = true;
227- pdata -> pend_proc ++ ;
228- k_sem_give (pdata -> sem );
225+ k_event_post (pdata -> event , DP_TASK_EVENT_PROCESS );
229226 }
230227
231228 if (curr_task -> state == SOF_TASK_STATE_RUNNING ) {
@@ -277,41 +274,18 @@ void dp_thread_fn(void *p1, void *p2, void *p3)
277274 comp_info (pmod -> dev , "userspace thread started" );
278275
279276 do {
280- /*
281- * The thread is started immediately after creation, it stops here and waits
282- * for the semaphore to be signalled to handle IPC or process audio data.
283- */
284- k_sem_take (task_pdata -> sem , K_FOREVER );
285-
286- lock_key = scheduler_dp_lock (task -> core );
287-
288- unsigned char pend_ipc = task_pdata -> pend_ipc ,
289- pend_proc = task_pdata -> pend_proc ;
290-
291- task_pdata -> pend_proc = 0 ;
292- task_pdata -> pend_ipc = 0 ;
293-
294- scheduler_dp_unlock (lock_key );
295-
296- /*
297- * Only 0:1, 1:0 and 1:1 are valid. 0:0 is also possible if IPC and audio
298- * were signalled in a quick succession before we took the lock above. Any
299- * value > 1 would mean that we've missed IPCs or LL ticks while in queued /
300- * idle state, which shouldn't happen.
301- */
302- if (pend_ipc > 1 || pend_proc > 1 ) {
303- tr_err (& dp_tr , "Invalid wake up %u:%u" , pend_proc , pend_ipc );
304- continue ;
305- }
277+ uint32_t mask = k_event_wait_safe (task_pdata -> event ,
278+ DP_TASK_EVENT_PROCESS | DP_TASK_EVENT_CANCEL |
279+ DP_TASK_EVENT_IPC , false, K_FOREVER );
306280
307- if (pend_ipc ) {
281+ if (mask & DP_TASK_EVENT_IPC ) {
308282 /* handle IPC */
309283 tr_dbg (& dp_tr , "got IPC wake up for %p state %d" , pmod , task -> state );
310284 ipc_thread_unflatten_run (pmod , task_pdata -> flat );
311285 k_sem_give (& dp_sync [task -> core ]);
312286 }
313287
314- if (pend_proc ) {
288+ if (mask & DP_TASK_EVENT_PROCESS ) {
315289 bool ready ;
316290
317291 if (task -> state == SOF_TASK_STATE_RUNNING ) {
@@ -455,8 +429,8 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
455429
456430 pdata -> flat = & task_memory -> flat ;
457431
458- pdata -> sem = k_object_alloc (K_OBJ_SEM );
459- if (!pdata -> sem ) {
432+ pdata -> event = k_object_alloc (K_OBJ_EVENT );
433+ if (!pdata -> event ) {
460434 tr_err (& dp_tr , "Event object allocation failed" );
461435 ret = - ENOMEM ;
462436 goto e_stack ;
@@ -493,7 +467,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
493467 goto e_thread ;
494468 }
495469
496- k_thread_access_grant (pdata -> thread_id , pdata -> sem , & dp_sync [core ]);
470+ k_thread_access_grant (pdata -> thread_id , pdata -> event , & dp_sync [core ]);
497471 scheduler_dp_grant (pdata -> thread_id , core );
498472
499473 unsigned int pidx ;
@@ -547,7 +521,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
547521 }
548522
549523 /* start the thread, it should immediately stop at the semaphore */
550- k_sem_init (pdata -> sem , 0 , 1 );
524+ k_event_init (pdata -> event );
551525 k_thread_start (pdata -> thread_id );
552526
553527 return 0 ;
@@ -559,7 +533,7 @@ int scheduler_dp_task_init(struct task **task, const struct sof_uuid_entry *uid,
559533e_kobj :
560534 /* k_object_free looks for a pointer in the list, any invalid value can be passed */
561535 k_object_free (pdata -> thread );
562- k_object_free (pdata -> sem );
536+ k_object_free (pdata -> event );
563537e_stack :
564538 user_stack_free (p_stack );
565539e_tmem :
0 commit comments