Skip to content

Commit bd095b3

Browse files
committed
schedule: add scheduler_init_context() and scheduler_free_context()
Add two optional ops 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 1f1ee4e commit bd095b3

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

src/include/sof/schedule/schedule.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,25 @@ 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);
171+
172+
/**
173+
* Frees scheduler context
174+
* @param data Private data of selected scheduler.
175+
*
176+
* This operation is optional.
177+
*/
178+
void (*scheduler_free_context)(void *data);
179+
161180
};
162181

163182
/** \brief Holds information about scheduler. */
@@ -379,6 +398,41 @@ static inline int schedulers_restore(void)
379398
return 0;
380399
}
381400

401+
402+
/** See scheduler_ops::scheduler_init_context */
403+
static inline struct k_thread *scheduler_init_context(struct task *task)
404+
{
405+
struct schedulers *schedulers = *arch_schedulers_get();
406+
struct schedule_data *sch;
407+
struct list_item *slist;
408+
409+
assert(schedulers);
410+
411+
list_for_item(slist, &schedulers->list) {
412+
sch = container_of(slist, struct schedule_data, list);
413+
if (sch->ops->scheduler_init_context)
414+
return sch->ops->scheduler_init_context(sch->data, task);
415+
}
416+
417+
return 0;
418+
}
419+
420+
/** See scheduler_ops::scheduler_free_context */
421+
static inline void scheduler_free_context(void)
422+
{
423+
struct schedulers *schedulers = *arch_schedulers_get();
424+
struct schedule_data *sch;
425+
struct list_item *slist;
426+
427+
assert(schedulers);
428+
429+
list_for_item(slist, &schedulers->list) {
430+
sch = container_of(slist, struct schedule_data, list);
431+
if (sch->ops->scheduler_free_context)
432+
sch->ops->scheduler_free_context(sch->data);
433+
}
434+
}
435+
382436
/**
383437
* Initializes scheduling task.
384438
* @param task Task to be initialized.

0 commit comments

Comments
 (0)