Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/lib/refcount.h

    r1a1e124 r4805495  
    4949} atomic_refcount_t;
    5050
    51 #define REFCOUNT_INITIALIZER() { \
    52         .__cnt = ATOMIC_VAR_INIT(0), \
    53 }
    54 
    5551static inline void refcount_init(atomic_refcount_t *rc)
    5652{
    57         atomic_init(&rc->__cnt, 0);
     53        atomic_store_explicit(&rc->__cnt, 0, memory_order_relaxed);
    5854}
    5955
     
    7874        assert(old >= 0);
    7975        (void) old;
    80 }
    81 
    82 /**
    83  * Try to upgrade a weak reference.
    84  * Naturally, this is contingent on another form of synchronization being used
    85  * to ensure that the object continues to exist while the weak reference is in
    86  * use.
    87  */
    88 static inline bool refcount_try_up(atomic_refcount_t *rc)
    89 {
    90         int cnt = atomic_load_explicit(&rc->__cnt, memory_order_relaxed);
    91 
    92         while (cnt >= 0) {
    93                 if (atomic_compare_exchange_weak_explicit(&rc->__cnt, &cnt, cnt + 1,
    94                     memory_order_relaxed, memory_order_relaxed)) {
    95                         return true;
    96                 }
    97         }
    98 
    99         return false;
    10076}
    10177
Note: See TracChangeset for help on using the changeset viewer.