tasks: add put_task_struct_many()
authorPavel Begunkov <asml.silence@gmail.com>
Sat, 18 Jul 2020 08:32:51 +0000 (11:32 +0300)
committerJens Axboe <axboe@kernel.dk>
Fri, 24 Jul 2020 19:00:45 +0000 (13:00 -0600)
put_task_struct_many() is as put_task_struct() but puts several
references at once. Useful to batching it.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/sched/task.h

index 38359071236ad7d81602f4f896335630c1f80035..1301077f9c24cdeff859f9d7b903da10384a8628 100644 (file)
@@ -126,6 +126,12 @@ static inline void put_task_struct(struct task_struct *t)
                __put_task_struct(t);
 }
 
+static inline void put_task_struct_many(struct task_struct *t, int nr)
+{
+       if (refcount_sub_and_test(nr, &t->usage))
+               __put_task_struct(t);
+}
+
 void put_task_struct_rcu_user(struct task_struct *task);
 
 #ifdef CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT