refcount.c (a976c2951d8f376112361830aa7762beff83a205) | refcount.c (fd25d19f6b8da315332bb75936605fb45d3ea981) |
---|---|
1/* 2 * Variant of atomic_t specialized for reference counts. 3 * 4 * The interface matches the atomic_t interface (to aid in porting) but only 5 * provides the few functions one should use for reference counting. 6 * 7 * It differs in that the counter saturates at UINT_MAX and will not move once 8 * there. This avoids wrapping the counter and causing 'spurious' --- 23 unchanged lines hidden (view full) --- 32 * Note that the allocator is responsible for ordering things between free() 33 * and alloc(). 34 * 35 */ 36 37#include <linux/refcount.h> 38#include <linux/bug.h> 39 | 1/* 2 * Variant of atomic_t specialized for reference counts. 3 * 4 * The interface matches the atomic_t interface (to aid in porting) but only 5 * provides the few functions one should use for reference counting. 6 * 7 * It differs in that the counter saturates at UINT_MAX and will not move once 8 * there. This avoids wrapping the counter and causing 'spurious' --- 23 unchanged lines hidden (view full) --- 32 * Note that the allocator is responsible for ordering things between free() 33 * and alloc(). 34 * 35 */ 36 37#include <linux/refcount.h> 38#include <linux/bug.h> 39 |
40#ifdef CONFIG_REFCOUNT_FULL 41 |
|
40/** 41 * refcount_add_not_zero - add a value to a refcount unless it is 0 42 * @i: the value to add to the refcount 43 * @r: the refcount 44 * 45 * Will saturate at UINT_MAX and WARN. 46 * 47 * Provides no memory ordering, it is assumed the caller has guaranteed the --- 172 unchanged lines hidden (view full) --- 220 * Provides release memory ordering, such that prior loads and stores are done 221 * before. 222 */ 223void refcount_dec(refcount_t *r) 224{ 225 WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); 226} 227EXPORT_SYMBOL(refcount_dec); | 42/** 43 * refcount_add_not_zero - add a value to a refcount unless it is 0 44 * @i: the value to add to the refcount 45 * @r: the refcount 46 * 47 * Will saturate at UINT_MAX and WARN. 48 * 49 * Provides no memory ordering, it is assumed the caller has guaranteed the --- 172 unchanged lines hidden (view full) --- 222 * Provides release memory ordering, such that prior loads and stores are done 223 * before. 224 */ 225void refcount_dec(refcount_t *r) 226{ 227 WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); 228} 229EXPORT_SYMBOL(refcount_dec); |
230#endif /* CONFIG_REFCOUNT_FULL */ |
|
228 229/** 230 * refcount_dec_if_one - decrement a refcount if it is 1 231 * @r: the refcount 232 * 233 * No atomic_t counterpart, it attempts a 1 -> 0 transition and returns the 234 * success thereof. 235 * --- 113 unchanged lines hidden --- | 231 232/** 233 * refcount_dec_if_one - decrement a refcount if it is 1 234 * @r: the refcount 235 * 236 * No atomic_t counterpart, it attempts a 1 -> 0 transition and returns the 237 * success thereof. 238 * --- 113 unchanged lines hidden --- |