Changeset 9f2f5ee in mainline for kernel/generic/include/synch/mutex.h


Ignore:
Timestamp:
2025-04-10T17:48:56Z (5 days ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
c55ab66
Parents:
c626117
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-10 10:55:54)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-10 17:48:56)
Message:

Rewrite kernel mutex implementation a little

Removes MUTEX_ACTIVE, the use of which has been removed in favor of
irq_spinlock_t, and fixes some issues with the old implementation.

  • A race in mtx→owner access is unavoidable, so make it explicitly atomic.
  • The THREAD==NULL case happens when there are no other threads yet, so we factor it out as a special case. Also ensures recursive mutex works before threads are initialized, just as normal mutex does.
  • More and better asserts.
File:
1 edited

Legend:

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

    rc626117 r9f2f5ee  
    4444        MUTEX_PASSIVE,
    4545        MUTEX_RECURSIVE,
    46         MUTEX_ACTIVE
    4746} mutex_type_t;
    4847
     
    5150typedef struct {
    5251        mutex_type_t type;
     52        int nesting;
    5353        semaphore_t sem;
    54         struct thread *owner;
    55         unsigned nesting;
     54        _Atomic(struct thread *) owner;
    5655} mutex_t;
    5756
    5857#define MUTEX_INITIALIZER(name, mtype) (mutex_t) { \
    5958        .type = (mtype), \
     59        .nesting = 0, \
    6060        .sem = SEMAPHORE_INITIALIZER((name).sem, 1), \
    6161        .owner = NULL, \
    62         .nesting = 0, \
    6362}
    6463
Note: See TracChangeset for help on using the changeset viewer.