Ignore:
File:
1 edited

Legend:

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

    r4805495 r1a1e124  
    4949} atomic_refcount_t;
    5050
     51#define REFCOUNT_INITIALIZER() { \
     52        .__cnt = ATOMIC_VAR_INIT(0), \
     53}
     54
    5155static inline void refcount_init(atomic_refcount_t *rc)
    5256{
    53         atomic_store_explicit(&rc->__cnt, 0, memory_order_relaxed);
     57        atomic_init(&rc->__cnt, 0);
    5458}
    5559
     
    7478        assert(old >= 0);
    7579        (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 */
     88static 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;
    76100}
    77101
Note: See TracChangeset for help on using the changeset viewer.