0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/sched/signal.h>
0009 #include <linux/sched/task.h>
0010 #include <linux/sched/mm.h>
0011
0012
0013
0014
0015 bool current_is_single_threaded(void)
0016 {
0017 struct task_struct *task = current;
0018 struct mm_struct *mm = task->mm;
0019 struct task_struct *p, *t;
0020 bool ret;
0021
0022 if (atomic_read(&task->signal->live) != 1)
0023 return false;
0024
0025 if (atomic_read(&mm->mm_users) == 1)
0026 return true;
0027
0028 ret = false;
0029 rcu_read_lock();
0030 for_each_process(p) {
0031 if (unlikely(p->flags & PF_KTHREAD))
0032 continue;
0033 if (unlikely(p == task->group_leader))
0034 continue;
0035
0036 for_each_thread(p, t) {
0037 if (unlikely(t->mm == mm))
0038 goto found;
0039 if (likely(t->mm))
0040 break;
0041
0042
0043
0044
0045
0046 smp_rmb();
0047 }
0048 }
0049 ret = true;
0050 found:
0051 rcu_read_unlock();
0052
0053 return ret;
0054 }