Changeset 0f4f1b2 in mainline for kernel/test/mm/falloc2.c


Ignore:
Timestamp:
2024-01-15T17:10:27Z (9 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
e82879c
Parents:
a064d4f
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 16:37:22)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 17:10:27)
Message:

Add (and use) functions thread_start() and thread_detach()

Mostly cosmetic, with thread_start() replacing calls to thread_ready(),
but not consuming the passed reference, and thread_detach() being
synonym for thread_put(). Makes the code's function more obvious.

Also modify some threaded tests to use thread_join() for waiting,
instead of counting threads with atomics or semaphores.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/mm/falloc2.c

    ra064d4f r0f4f1b2  
    4343#define THREADS      8
    4444
    45 static atomic_size_t thread_cnt;
    4645static atomic_size_t thread_fail;
    4746
     
    5655                    "Unable to allocate frames\n", THREAD->tid, CPU->id);
    5756                atomic_inc(&thread_fail);
    58                 atomic_dec(&thread_cnt);
    5957                return;
    6058        }
     
    108106        TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n",
    109107            THREAD->tid, CPU->id);
    110         atomic_dec(&thread_cnt);
    111108}
    112109
    113110const char *test_falloc2(void)
    114111{
    115         atomic_store(&thread_cnt, THREADS);
    116112        atomic_store(&thread_fail, 0);
     113
     114        thread_t *threads[THREADS] = { };
    117115
    118116        for (unsigned int i = 0; i < THREADS; i++) {
     
    123121                        break;
    124122                }
    125                 thread_ready(thrd);
     123                thread_start(thrd);
     124                threads[i] = thrd;
    126125        }
    127126
    128         while (atomic_load(&thread_cnt) > 0) {
    129                 TPRINTF("Threads left: %zu\n",
    130                     atomic_load(&thread_cnt));
    131                 thread_sleep(1);
     127        for (unsigned int i = 0; i < THREADS; i++) {
     128                if (threads[i] != NULL)
     129                        thread_join(threads[i]);
     130
     131                TPRINTF("Threads left: %u\n", THREADS - i - 1);
    132132        }
    133133
Note: See TracChangeset for help on using the changeset viewer.