Skip to content

Commit 8f4e140

Browse files
committed
schedule: add scheduler_init_context()
Add an optional method that allow the schedule.h user to get access to the thread context that will be used for scheduling. This is critical when the callbacks are run in user-space context and schedule.h client needs to grant access to objects like locks to the callback thread. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent efbc17b commit 8f4e140

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/include/sof/schedule/schedule.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ struct scheduler_ops {
158158
* This operation is optional.
159159
*/
160160
int (*scheduler_restore)(void *data);
161+
162+
/**
163+
* Initializes context
164+
* @param data Private data of selected scheduler.
165+
* @param task task that needs to be scheduled
166+
* @return thread that will be used to run the scheduled task
167+
*
168+
* This operation is optional.
169+
*/
170+
struct k_thread *(*scheduler_init_context)(void *data, struct task *task);
161171
};
162172

163173
/** \brief Holds information about scheduler. */
@@ -379,6 +389,24 @@ static inline int schedulers_restore(void)
379389
return 0;
380390
}
381391

392+
/** See scheduler_ops::scheduler_init_context */
393+
static inline struct k_thread *scheduler_init_context(struct task *task)
394+
{
395+
struct schedulers *schedulers = *arch_schedulers_get();
396+
struct schedule_data *sch;
397+
struct list_item *slist;
398+
399+
assert(schedulers);
400+
401+
list_for_item(slist, &schedulers->list) {
402+
sch = container_of(slist, struct schedule_data, list);
403+
if (task->type == sch->type && sch->ops->scheduler_init_context)
404+
return sch->ops->scheduler_init_context(sch->data, task);
405+
}
406+
407+
return NULL;
408+
}
409+
382410
/**
383411
* Initializes scheduling task.
384412
* @param task Task to be initialized.

0 commit comments

Comments
 (0)