Changes in kernel/generic/include/lib/refcount.h [4805495:1a1e124] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/lib/refcount.h
r4805495 r1a1e124 49 49 } atomic_refcount_t; 50 50 51 #define REFCOUNT_INITIALIZER() { \ 52 .__cnt = ATOMIC_VAR_INIT(0), \ 53 } 54 51 55 static inline void refcount_init(atomic_refcount_t *rc) 52 56 { 53 atomic_ store_explicit(&rc->__cnt, 0, memory_order_relaxed);57 atomic_init(&rc->__cnt, 0); 54 58 } 55 59 … … 74 78 assert(old >= 0); 75 79 (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; 76 100 } 77 101
Note:
See TracChangeset
for help on using the changeset viewer.