Add percpu_ref_tryget_many(), which works the same way as percpu_ref_tryget(), but grabs specified number of refs.
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -210,15 +210,17 @@ static inline void percpu_ref_get(struct percpu_ref *ref) · 209 unmodified lines | ||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | − * percpu_ref_tryget - try to increment a percpu refcount | |
| 213 | + * percpu_ref_tryget_many - try to increment a percpu refcount | |
| 214 | 214 | * @ref: percpu_ref to try-get |
| 215 | + * @nr: number of references to get | |
| 215 | 216 | * |
| 216 | − * Increment a percpu refcount unless its count already reached zero. | |
| 217 | + * Increment a percpu refcount by @nr unless its count already reached zero. | |
| 217 | 218 | * Returns %true on success; %false on failure. |
| 218 | 219 | * |
| 219 | 220 | * This function is safe to call as long as @ref is between init and exit. |
| 220 | 221 | */ |
| 221 | −static inline bool percpu_ref_tryget(struct percpu_ref *ref) | |
| 222 | +static inline bool percpu_ref_tryget_many(struct percpu_ref *ref, | |
| 223 | + unsigned long nr) | |
| 222 | 224 | { |
| 223 | 225 | unsigned long __percpu *percpu_count; |
| 224 | 226 | bool ret; |
| @@ -226,10 +228,10 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) · 1 unmodified line | ||
| 226 | 228 | rcu_read_lock(); |
| 227 | 229 | |
| 228 | 230 | if (__ref_is_percpu(ref, &percpu_count)) { |
| 229 | − this_cpu_inc(*percpu_count); | |
| 231 | + this_cpu_add(*percpu_count, nr); | |
| 230 | 232 | ret = true; |
| 231 | 233 | } else { |
| 232 | − ret = atomic_long_inc_not_zero(&ref->count); | |
| 234 | + ret = atomic_long_add_unless(&ref->count, nr, 0); | |
| 233 | 235 | } |
| 234 | 236 | |
| 235 | 237 | rcu_read_unlock(); |
| @@ -237,6 +239,20 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) · 1 unmodified line | ||
| 237 | 239 | return ret; |
| 238 | 240 | } |
| 239 | 241 | |
| 242 | +/** | |
| 243 | + * percpu_ref_tryget - try to increment a percpu refcount | |
| 244 | + * @ref: percpu_ref to try-get | |
| 245 | + * | |
| 246 | + * Increment a percpu refcount unless its count already reached zero. | |
| 247 | + * Returns %true on success; %false on failure. | |
| 248 | + * | |
| 249 | + * This function is safe to call as long as @ref is between init and exit. | |
| 250 | + */ | |
| 251 | +static inline bool percpu_ref_tryget(struct percpu_ref *ref) | |
| 252 | +{ | |
| 253 | + return percpu_ref_tryget_many(ref, 1); | |
| 254 | +} | |
| 255 | + | |
| 240 | 256 | /** |
| 241 | 257 | * percpu_ref_tryget_live - try to increment a live percpu refcount |
| 242 | 258 | * @ref: percpu_ref to try-get |