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


Ignore:
Timestamp:
2024-01-15T17:10:27Z (11 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/slab2.c

    ra064d4f r0f4f1b2  
    127127
    128128static slab_cache_t *thr_cache;
    129 static semaphore_t thr_sem;
    130129static condvar_t thread_starter;
    131130static mutex_t starter_mutex;
     
    188187        if (!test_quiet)
    189188                slab_print_list();
    190 
    191         semaphore_up(&thr_sem);
    192189}
    193190
     
    198195         * then release everything, then again allocate, then release
    199196         */
    200         thread_t *t;
    201         int i;
    202197
    203198        TPRINTF("Running stress test with size %d\n", size);
     
    207202
    208203        thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
    209         semaphore_initialize(&thr_sem, 0);
    210         for (i = 0; i < THREADS; i++) {
    211                 if (!(t = thread_create(slabtest, NULL, TASK, THREAD_FLAG_NONE, "slabtest"))) {
     204
     205        thread_t *threads[THREADS] = { };
     206
     207        for (int i = 0; i < THREADS; i++) {
     208                threads[i] = thread_create(slabtest, NULL,
     209                    TASK, THREAD_FLAG_NONE, "slabtest");
     210                if (threads[i]) {
     211                        thread_start(threads[i]);
     212                } else {
    212213                        TPRINTF("Could not create thread %d\n", i);
    213                 } else
    214                         thread_ready(t);
    215         }
     214                }
     215        }
     216
    216217        thread_sleep(1);
    217218        condvar_broadcast(&thread_starter);
    218219
    219         for (i = 0; i < THREADS; i++)
    220                 semaphore_down(&thr_sem);
     220        for (int i = 0; i < THREADS; i++) {
     221                if (threads[i] != NULL)
     222                        thread_join(threads[i]);
     223        }
    221224
    222225        slab_cache_destroy(thr_cache);
Note: See TracChangeset for help on using the changeset viewer.