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


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.