Changeset aab5e46 in mainline for kernel/generic/src


Ignore:
Timestamp:
2018-11-03T23:32:39Z (7 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.

Location:
kernel/generic/src
Files:
3 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
  • kernel/generic/src/proc/thread.c

    ref1eab7 raab5e46  
    772772void thread_print_list(bool additional)
    773773{
    774         odlink_t *odlink;
    775774        thread_t *thread;
    776775
     
    796795#endif
    797796
    798         odlink = odict_first(&threads);
    799         while (odlink != NULL) {
    800                 thread = odict_get_instance(odlink, thread_t, lthreads);
     797        thread = thread_first();
     798        while (thread != NULL) {
    801799                thread_print(thread, additional);
    802                 odlink = odict_next(odlink, &threads);
     800                thread = thread_next(thread);
    803801        }
    804802
     
    860858thread_t *thread_find_by_id(thread_id_t thread_id)
    861859{
    862         odlink_t *odlink;
    863860        thread_t *thread;
    864861
     
    866863        assert(irq_spinlock_locked(&threads_lock));
    867864
    868         odlink = odict_first(&threads);
    869         while (odlink != NULL) {
    870                 thread = odict_get_instance(odlink, thread_t, lthreads);
     865        thread = thread_first();
     866        while (thread != NULL) {
    871867                if (thread->tid == thread_id)
    872868                        return thread;
    873869
    874                 odlink = odict_next(odlink, &threads);
     870                thread = thread_next(thread);
    875871        }
    876872
    877873        return NULL;
     874}
     875
     876/** Get count of threads.
     877 *
     878 * @return Number of threads in the system
     879 */
     880size_t thread_count(void)
     881{
     882        assert(interrupts_disabled());
     883        assert(irq_spinlock_locked(&threads_lock));
     884
     885        return odict_count(&threads);
     886}
     887
     888/** Get first thread.
     889 *
     890 * @return Pointer to first thread or @c NULL if there are none.
     891 */
     892thread_t *thread_first(void)
     893{
     894        odlink_t *odlink;
     895
     896        assert(interrupts_disabled());
     897        assert(irq_spinlock_locked(&threads_lock));
     898
     899        odlink = odict_first(&threads);
     900        if (odlink == NULL)
     901                return NULL;
     902
     903        return odict_get_instance(odlink, thread_t, lthreads);
     904}
     905
     906/** Get next thread.
     907 *
     908 * @param cur Current thread
     909 * @return Pointer to next thread or @c NULL if there are no more threads.
     910 */
     911thread_t *thread_next(thread_t *cur)
     912{
     913        odlink_t *odlink;
     914
     915        assert(interrupts_disabled());
     916        assert(irq_spinlock_locked(&threads_lock));
     917
     918        odlink = odict_next(&cur->lthreads, &threads);
     919        if (odlink == NULL)
     920                return NULL;
     921
     922        return odict_get_instance(odlink, thread_t, lthreads);
    878923}
    879924
  • kernel/generic/src/sysinfo/stats.c

    ref1eab7 raab5e46  
    246246
    247247        /* Count the tasks */
    248         size_t count = odict_count(&tasks);
     248        size_t count = task_count();
    249249
    250250        if (count == 0) {
     
    271271        /* Gather the statistics for each task */
    272272        size_t i = 0;
    273         odlink_t *odlink = odict_first(&tasks);
    274         while (odlink != NULL) {
    275                 task_t *task = odict_get_instance(odlink, task_t, ltasks);
    276 
     273        task_t *task = task_first();
     274        while (task != NULL) {
    277275                /* Interrupts are already disabled */
    278276                irq_spinlock_lock(&(task->lock), false);
     
    283281
    284282                irq_spinlock_unlock(&(task->lock), false);
    285                 odlink = odict_next(odlink, &tasks);
     283                task = task_next(task);
    286284        }
    287285
     
    336334
    337335        /* Count the threads */
    338         size_t count = odict_count(&threads);
     336        size_t count = thread_count();
    339337
    340338        if (count == 0) {
     
    362360        size_t i = 0;
    363361
    364         odlink_t *odlink = odict_first(&threads);
    365         while (odlink != NULL) {
    366                 thread_t *thread = odict_get_instance(odlink, thread_t,
    367                     lthreads);
    368 
     362        thread_t *thread = thread_first();
     363        while (thread != NULL) {
    369364                /* Interrupts are already disabled */
    370365                irq_spinlock_lock(&thread->lock, false);
     
    376371                irq_spinlock_unlock(&thread->lock, false);
    377372
    378                 odlink = odict_next(odlink, &threads);
     373                thread = thread_next(thread);
    379374        }
    380375
Note: See TracChangeset for help on using the changeset viewer.