Changes in kernel/generic/include/lib/refcount.h [1a1e124:4805495] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/lib/refcount.h
r1a1e124 r4805495 49 49 } atomic_refcount_t; 50 50 51 #define REFCOUNT_INITIALIZER() { \52 .__cnt = ATOMIC_VAR_INIT(0), \53 }54 55 51 static inline void refcount_init(atomic_refcount_t *rc) 56 52 { 57 atomic_ init(&rc->__cnt, 0);53 atomic_store_explicit(&rc->__cnt, 0, memory_order_relaxed); 58 54 } 59 55 … … 78 74 assert(old >= 0); 79 75 (void) old; 80 }81 82 /**83 * Try to upgrade a weak reference.84 * Naturally, this is contingent on another form of synchronization being used85 * to ensure that the object continues to exist while the weak reference is in86 * 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;100 76 } 101 77
Note:
See TracChangeset
for help on using the changeset viewer.