Changeset aab5e46 in mainline for kernel/generic/src/proc/task.c


Ignore:
Timestamp:
2018-11-03T23:32:39Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
790f3a3
Parents:
ef1eab7
Message:

Thread and task iterator functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/task.c

    ref1eab7 raab5e46  
    107107{
    108108        size_t tasks_left;
    109         odlink_t *odlink;
    110109        task_t *task;
    111110
     
    128127                tasks_left = 0;
    129128
    130                 odlink = odict_first(&tasks);
    131                 while (odlink != NULL) {
    132                         task = odict_get_instance(odlink, task_t, ltasks);
    133 
     129                task = task_first();
     130                while (task != NULL) {
    134131                        if (task != TASK) {
    135132                                tasks_left++;
     
    140137                        }
    141138
    142                         odlink = odict_next(odlink, &tasks);
     139                        task = task_next(task);
    143140                }
    144141
     
    452449}
    453450
     451/** Get count of tasks.
     452 *
     453 * @return Number of tasks in the system
     454 */
     455size_t task_count(void)
     456{
     457        assert(interrupts_disabled());
     458        assert(irq_spinlock_locked(&tasks_lock));
     459
     460        return odict_count(&tasks);
     461}
     462
     463/** Get first task (task with lowest ID).
     464 *
     465 * @return Pointer to first task or @c NULL if there are none.
     466 */
     467task_t *task_first(void)
     468{
     469        odlink_t *odlink;
     470
     471        assert(interrupts_disabled());
     472        assert(irq_spinlock_locked(&tasks_lock));
     473
     474        odlink = odict_first(&tasks);
     475        if (odlink == NULL)
     476                return NULL;
     477
     478        return odict_get_instance(odlink, task_t, ltasks);
     479}
     480
     481/** Get next task (with higher task ID).
     482 *
     483 * @param cur Current task
     484 * @return Pointer to next task or @c NULL if there are no more tasks.
     485 */
     486task_t *task_next(task_t *cur)
     487{
     488        odlink_t *odlink;
     489
     490        assert(interrupts_disabled());
     491        assert(irq_spinlock_locked(&tasks_lock));
     492
     493        odlink = odict_next(&cur->ltasks, &tasks);
     494        if (odlink == NULL)
     495                return NULL;
     496
     497        return odict_get_instance(odlink, task_t, ltasks);
     498}
     499
    454500/** Get accounting data of given task.
    455501 *
     
    658704#endif
    659705
    660         odlink_t *odlink;
    661706        task_t *task;
    662707
    663         odlink = odict_first(&tasks);
    664         while (odlink != NULL) {
    665                 task = odict_get_instance(odlink, task_t, ltasks);
     708        task = task_first();
     709        while (task != NULL) {
    666710                task_print(task, additional);
    667                 odlink = odict_next(odlink, &tasks);
     711                task = task_next(task);
    668712        }
    669713
Note: See TracChangeset for help on using the changeset viewer.