Changeset 9f945464 in mainline


Ignore:
Timestamp:
2025-04-09T16:36:30Z (5 days ago)
Author:
GitHub <noreply@…>
Children:
3acb63b5
Parents:
2c94501 (diff), 597fa24 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Wayne Thornton <wmthornton-dev@…> (2025-04-09 16:36:30)
git-committer:
GitHub <noreply@…> (2025-04-09 16:36:30)
Message:

Merge pull request #3 from HelenOS/master

Enable static initialization of kernel synchronization primitives

Location:
kernel
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/synch/condvar.h

    r2c94501 r9f945464  
    4646} condvar_t;
    4747
     48#define CONDVAR_INITIALIZER(name) (condvar_t) { \
     49        .wq = WAITQ_INITIALIZER((name).wq), \
     50}
     51
     52#define CONDVAR_INITIALIZE(name) \
     53        condvar_t name = CONDVAR_INITIALIZER(name)
     54
    4855#ifdef CONFIG_SMP
    4956#define _condvar_wait_timeout_spinlock(cv, lock, usec, flags) \
  • kernel/generic/include/synch/mutex.h

    r2c94501 r9f945464  
    5656} mutex_t;
    5757
     58#define MUTEX_INITIALIZER(name, mtype) (mutex_t) { \
     59        .type = (mtype), \
     60        .sem = SEMAPHORE_INITIALIZER((name).sem, 1), \
     61        .owner = NULL, \
     62        .nesting = 0, \
     63}
     64
     65#define MUTEX_INITIALIZE(name, mtype) \
     66        mutex_t name = MUTEX_INITIALIZER(name, mtype)
     67
    5868extern void mutex_initialize(mutex_t *, mutex_type_t);
    5969extern bool mutex_locked(mutex_t *);
  • kernel/generic/include/synch/semaphore.h

    r2c94501 r9f945464  
    4545} semaphore_t;
    4646
     47#define SEMAPHORE_INITIALIZER(name, count) (semaphore_t) { \
     48        .wq = WAITQ_INITIALIZER_WITH_COUNT((name).wq, count), \
     49}
     50
     51#define SEMAPHORE_INITIALIZE(name, count) \
     52        semaphore_t name = SEMAPHORE_INITIALIZER(name, count)
     53
    4754extern void semaphore_initialize(semaphore_t *, int);
    4855extern errno_t semaphore_down_timeout(semaphore_t *, uint32_t);
  • kernel/generic/include/synch/waitq.h

    r2c94501 r9f945464  
    4040#include <abi/synch.h>
    4141#include <adt/list.h>
     42
     43#define WAITQ_INITIALIZER_WITH_COUNT(name, count) (waitq_t) { \
     44        .lock = IRQ_SPINLOCK_INITIALIZER(#name ".lock"), \
     45        .sleepers = LIST_INITIALIZER((name).sleepers), \
     46        .wakeup_balance = (count), \
     47}
     48
     49#define WAITQ_INITIALIZER(name) WAITQ_INITIALIZER_WITH_COUNT(name, 0)
     50
     51#define WAITQ_INITIALIZE_WITH_COUNT(name, count) \
     52        waitq_t name = WAITQ_INITIALIZER_WITH_COUNT(name, count)
     53
     54#define WAITQ_INITIALIZE(name) \
     55        waitq_t name = WAITQ_INITIALIZER(name)
    4256
    4357/** Wait queue structure.
  • kernel/generic/src/ddi/ddi.c

    r2c94501 r9f945464  
    6060
    6161/** This lock protects the @c pareas ordered dictionary. */
    62 static mutex_t pareas_lock;
     62static MUTEX_INITIALIZE(pareas_lock, MUTEX_PASSIVE);
    6363
    6464/** Ordered dictionary of enabled physical memory areas by base address. */
     
    7474{
    7575        odict_initialize(&pareas, pareas_getkey, pareas_cmp);
    76         mutex_initialize(&pareas_lock, MUTEX_PASSIVE);
    7776}
    7877
  • kernel/generic/src/main/main.c

    r2c94501 r9f945464  
    5353#include <stdio.h>
    5454#include <panic.h>
    55 #include <assert.h>
    5655#include <config.h>
    5756#include <time/clock.h>
  • kernel/generic/src/mm/frame.c

    r2c94501 r9f945464  
    6363#include <proc/thread.h> /* THREAD */
    6464
    65 zones_t zones;
     65zones_t zones = {
     66        .count = 0,
     67        .lock = IRQ_SPINLOCK_INITIALIZER("frame.zones.lock"),
     68};
    6669
    6770/*
     
    6972 * available.
    7073 */
    71 static mutex_t mem_avail_mtx;
    72 static condvar_t mem_avail_cv;
     74static MUTEX_INITIALIZE(mem_avail_mtx, MUTEX_ACTIVE);
     75static CONDVAR_INITIALIZE(mem_avail_cv);
    7376static size_t mem_avail_req = 0;  /**< Number of frames requested. */
    7477static size_t mem_avail_gen = 0;  /**< Generation counter. */
     
    11081111void frame_init(void)
    11091112{
    1110         if (config.cpu_active == 1) {
    1111                 zones.count = 0;
    1112                 irq_spinlock_initialize(&zones.lock, "frame.zones.lock");
    1113                 mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE);
    1114                 condvar_initialize(&mem_avail_cv);
    1115         }
    1116 
    11171113        /* Tell the architecture to create some memory */
    11181114        frame_low_arch_init();
  • kernel/generic/src/proc/thread.c

    r2c94501 r9f945464  
    667667void thread_usleep(uint32_t usec)
    668668{
    669         waitq_t wq;
    670 
    671         waitq_initialize(&wq);
    672 
     669        WAITQ_INITIALIZE(wq);
    673670        (void) waitq_sleep_timeout(&wq, usec);
    674671}
  • kernel/generic/src/synch/condvar.c

    r2c94501 r9f945464  
    4848void condvar_initialize(condvar_t *cv)
    4949{
    50         waitq_initialize(&cv->wq);
     50        *cv = CONDVAR_INITIALIZER(*cv);
    5151}
    5252
  • kernel/generic/src/synch/mutex.c

    r2c94501 r9f945464  
    5353void mutex_initialize(mutex_t *mtx, mutex_type_t type)
    5454{
    55         mtx->type = type;
    56         mtx->owner = NULL;
    57         mtx->nesting = 0;
    58         semaphore_initialize(&mtx->sem, 1);
     55        *mtx = MUTEX_INITIALIZER(*mtx, type);
    5956}
    6057
  • kernel/generic/src/synch/semaphore.c

    r2c94501 r9f945464  
    5252void semaphore_initialize(semaphore_t *sem, int val)
    5353{
    54         waitq_initialize_with_count(&sem->wq, val);
     54        *sem = SEMAPHORE_INITIALIZER(*sem, val);
    5555}
    5656
  • kernel/generic/src/synch/waitq.c

    r2c94501 r9f945464  
    7070void waitq_initialize(waitq_t *wq)
    7171{
    72         memsetb(wq, sizeof(*wq), 0);
    73         irq_spinlock_initialize(&wq->lock, "wq.lock");
    74         list_initialize(&wq->sleepers);
     72        *wq = WAITQ_INITIALIZER(*wq);
    7573}
    7674
     
    8179void waitq_initialize_with_count(waitq_t *wq, int count)
    8280{
    83         waitq_initialize(wq);
    84         wq->wakeup_balance = count;
     81        *wq = WAITQ_INITIALIZER_WITH_COUNT(*wq, count);
    8582}
    8683
  • kernel/generic/src/sysinfo/stats.c

    r2c94501 r9f945464  
    9090
    9191/** Load calculation lock */
    92 static mutex_t load_lock;
     92static MUTEX_INITIALIZE(load_lock, MUTEX_PASSIVE);
    9393
    9494/** Get statistics of all CPUs
     
    846846void stats_init(void)
    847847{
    848         mutex_initialize(&load_lock, MUTEX_PASSIVE);
    849 
    850848        sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL);
    851849        sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL);
  • kernel/generic/src/sysinfo/sysinfo.c

    r2c94501 r9f945464  
    5757
    5858/** Sysinfo lock */
    59 static mutex_t sysinfo_lock;
     59static MUTEX_INITIALIZE(sysinfo_lock, MUTEX_ACTIVE);
    6060
    6161/** Sysinfo item constructor
     
    102102            sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
    103103            sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
    104 
    105         mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);
    106104}
    107105
  • kernel/test/mm/slab2.c

    r2c94501 r9f945464  
    127127
    128128static slab_cache_t *thr_cache;
    129 static condvar_t thread_starter;
    130 static mutex_t starter_mutex;
     129static CONDVAR_INITIALIZE(thread_starter);
     130static MUTEX_INITIALIZE(starter_mutex, MUTEX_PASSIVE);
    131131
    132132#define THREADS  8
     
    197197
    198198        TPRINTF("Running stress test with size %d\n", size);
    199 
    200         condvar_initialize(&thread_starter);
    201         mutex_initialize(&starter_mutex, MUTEX_PASSIVE);
    202199
    203200        thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
Note: See TracChangeset for help on using the changeset viewer.