]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - lib/is_single_threaded.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-artful-kernel.git] / lib / is_single_threaded.c
CommitLineData
6cc88bc4
DH
1/* Function to determine if a thread group is single threaded or not
2 *
3 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from security/selinux/hooks.c
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
11 */
3f07c014 12#include <linux/sched/signal.h>
6cc88bc4 13
d2e3ee9b
ON
14/*
15 * Returns true if the task does not share ->mm with another thread/process.
6cc88bc4 16 */
5bb459bb 17bool current_is_single_threaded(void)
6cc88bc4 18{
5bb459bb 19 struct task_struct *task = current;
d2e3ee9b
ON
20 struct mm_struct *mm = task->mm;
21 struct task_struct *p, *t;
22 bool ret;
23
d2e3ee9b
ON
24 if (atomic_read(&task->signal->live) != 1)
25 return false;
6cc88bc4 26
d2e3ee9b
ON
27 if (atomic_read(&mm->mm_users) == 1)
28 return true;
29
30 ret = false;
d2e3ee9b
ON
31 rcu_read_lock();
32 for_each_process(p) {
33 if (unlikely(p->flags & PF_KTHREAD))
34 continue;
35 if (unlikely(p == task->group_leader))
36 continue;
37
90224350 38 for_each_thread(p, t) {
d2e3ee9b
ON
39 if (unlikely(t->mm == mm))
40 goto found;
41 if (likely(t->mm))
42 break;
967cc537
ON
43 /*
44 * t->mm == NULL. Make sure next_thread/next_task
45 * will see other CLONE_VM tasks which might be
46 * forked before exiting.
47 */
48 smp_rmb();
90224350 49 }
d2e3ee9b
ON
50 }
51 ret = true;
52found:
53 rcu_read_unlock();
6cc88bc4 54
d2e3ee9b 55 return ret;
6cc88bc4 56}