Changeset fc10e1b in mainline for kernel/generic/include


Ignore:
Timestamp:
2018-09-07T16:34:11Z (7 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d2c91ab
Parents:
508b0df1 (diff), e90cfa6 (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.
Message:

Merge branch 'atomic'

Use more of <stdatomic.h> in kernel. Increment/decrement macros kept because
the are handy. atomic_t currently kept because I'm way too lazy to go through
all uses and think about the most appropriate replacement.

Location:
kernel/generic/include
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/cht.h

    r508b0df1 rfc10e1b  
    3636#define KERN_CONC_HASH_TABLE_H_
    3737
     38#include <atomic.h>
    3839#include <stdint.h>
    3940#include <adt/list.h>
  • kernel/generic/include/atomic.h

    r508b0df1 rfc10e1b  
    4040#include <stdatomic.h>
    4141
    42 typedef size_t atomic_count_t;
    43 typedef ssize_t atomic_signed_t;
     42// TODO: Remove.
     43// Before <stdatomic.h> was available, there was only one atomic type
     44// equivalent to atomic_size_t. This means that in some places, atomic_t can
     45// be replaced with a more appropriate type (e.g. atomic_bool for flags or
     46// a signed type for potentially signed values).
     47// So atomic_t should be replaced with the most appropriate type on a case by
     48// case basis, and after there are no more uses, remove this type.
     49typedef atomic_size_t atomic_t;
    4450
    45 #define PRIua  "zu"          /**< Format for atomic_count_t. */
     51#define atomic_predec(val) \
     52        (atomic_fetch_sub((val), 1) - 1)
    4653
    47 typedef struct {
    48         volatile atomic_size_t count;
    49 } atomic_t;
     54#define atomic_preinc(val) \
     55        (atomic_fetch_add((val), 1) + 1)
    5056
    51 static inline void atomic_set(atomic_t *val, atomic_count_t i)
    52 {
    53         atomic_store(&val->count, i);
    54 }
     57#define atomic_postdec(val) \
     58        atomic_fetch_sub((val), 1)
    5559
    56 static inline atomic_count_t atomic_get(atomic_t *val)
    57 {
    58         return atomic_load(&val->count);
    59 }
     60#define atomic_postinc(val) \
     61        atomic_fetch_add((val), 1)
    6062
    61 static inline size_t atomic_predec(atomic_t *val)
    62 {
    63         return atomic_fetch_sub(&val->count, 1) - 1;
    64 }
     63#define atomic_dec(val) \
     64        ((void) atomic_fetch_sub(val, 1))
    6565
    66 static inline size_t atomic_preinc(atomic_t *val)
    67 {
    68         return atomic_fetch_add(&val->count, 1) + 1;
    69 }
    70 
    71 static inline size_t atomic_postdec(atomic_t *val)
    72 {
    73         return atomic_fetch_sub(&val->count, 1);
    74 }
    75 
    76 static inline size_t atomic_postinc(atomic_t *val)
    77 {
    78         return atomic_fetch_add(&val->count, 1);
    79 }
    80 
    81 static inline void atomic_dec(atomic_t *val)
    82 {
    83         atomic_fetch_sub(&val->count, 1);
    84 }
    85 
    86 static inline void atomic_inc(atomic_t *val)
    87 {
    88         atomic_fetch_add(&val->count, 1);
    89 }
     66#define atomic_inc(val) \
     67        ((void) atomic_fetch_add(val, 1))
    9068
    9169#define local_atomic_exchange(var_addr, new_val) \
    9270        atomic_exchange_explicit(var_addr, new_val, memory_order_relaxed)
    93 
    94 static inline bool test_and_set(atomic_t *val)
    95 {
    96         return atomic_exchange(&val->count, 1);
    97 }
    98 
    9971
    10072#endif
  • kernel/generic/include/mm/as.h

    r508b0df1 rfc10e1b  
    4848#include <lib/elf.h>
    4949#include <arch.h>
     50#include <lib/refcount.h>
    5051
    5152#define AS                   THE->as
     
    111112
    112113        /** Number of references (i.e. tasks that reference this as). */
    113         atomic_t refcount;
     114        atomic_refcount_t refcount;
    114115
    115116        mutex_t lock;
  • kernel/generic/include/synch/spinlock.h

    r508b0df1 rfc10e1b  
    3636#define KERN_SPINLOCK_H_
    3737
     38#include <assert.h>
     39#include <stdatomic.h>
    3840#include <stdbool.h>
    39 #include <barrier.h>
    40 #include <assert.h>
    4141#include <preemption.h>
    42 #include <atomic.h>
    4342#include <arch/asm.h>
    4443
     
    4645
    4746typedef struct spinlock {
    48         atomic_t val;
     47        atomic_flag flag;
    4948
    5049#ifdef CONFIG_DEBUG_SPINLOCK
     
    7069        spinlock_t lock_name = { \
    7170                .name = desc_name, \
    72                 .val = { 0 } \
     71                .flag = ATOMIC_FLAG_INIT \
    7372        }
    7473
     
    7675        static spinlock_t lock_name = { \
    7776                .name = desc_name, \
    78                 .val = { 0 } \
     77                .flag = ATOMIC_FLAG_INIT \
    7978        }
    8079
     
    8988#define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
    9089        spinlock_t lock_name = { \
    91                 .val = { 0 } \
     90                .flag = ATOMIC_FLAG_INIT \
    9291        }
    9392
    9493#define SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
    9594        static spinlock_t lock_name = { \
    96                 .val = { 0 } \
     95                .flag = ATOMIC_FLAG_INIT \
    9796        }
    9897
     
    126125NO_TRACE static inline void spinlock_unlock_nondebug(spinlock_t *lock)
    127126{
    128         /*
    129          * Prevent critical section code from bleeding out this way down.
    130          */
    131         CS_LEAVE_BARRIER();
    132 
    133         atomic_set(&lock->val, 0);
     127        atomic_flag_clear_explicit(&lock->flag, memory_order_release);
    134128        preemption_enable();
    135129}
     
    215209                .lock = { \
    216210                        .name = desc_name, \
    217                         .val = { 0 } \
     211                        .flag = ATOMIC_FLAG_INIT \
    218212                }, \
    219213                .guard = false, \
     
    225219                .lock = { \
    226220                        .name = desc_name, \
    227                         .val = { 0 } \
     221                        .flag = ATOMIC_FLAG_INIT \
    228222                }, \
    229223                .guard = false, \
     
    236230        irq_spinlock_t lock_name = { \
    237231                .lock = { \
    238                         .val = { 0 } \
     232                        .flag = ATOMIC_FLAG_INIT \
    239233                }, \
    240234                .guard = false, \
     
    245239        static irq_spinlock_t lock_name = { \
    246240                .lock = { \
    247                         .val = { 0 } \
     241                        .flag = ATOMIC_FLAG_INIT \
    248242                }, \
    249243                .guard = false, \
Note: See TracChangeset for help on using the changeset viewer.