diff options
| author | James Morris <jmorris@namei.org> | 2009-09-10 18:04:49 -0400 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2009-09-10 18:04:49 -0400 |
| commit | a3c8b97396ef42edfb845788ba6f53b2a93ce980 (patch) | |
| tree | 530c5bdbc534618311dab3e0af245835af56db0f /lib/is_single_threaded.c | |
| parent | 74fca6a42863ffacaf7ba6f1936a9f228950f657 (diff) | |
| parent | 9f0ab4a3f0fdb1ff404d150618ace2fa069bb2e1 (diff) | |
Merge branch 'next' into for-linus
Diffstat (limited to 'lib/is_single_threaded.c')
| -rw-r--r-- | lib/is_single_threaded.c | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c index f1ed2fe76c65..bd2bea963364 100644 --- a/lib/is_single_threaded.c +++ b/lib/is_single_threaded.c | |||
| @@ -12,34 +12,47 @@ | |||
| 12 | 12 | ||
| 13 | #include <linux/sched.h> | 13 | #include <linux/sched.h> |
| 14 | 14 | ||
| 15 | /** | 15 | /* |
| 16 | * is_single_threaded - Determine if a thread group is single-threaded or not | 16 | * Returns true if the task does not share ->mm with another thread/process. |
| 17 | * @p: A task in the thread group in question | ||
| 18 | * | ||
| 19 | * This returns true if the thread group to which a task belongs is single | ||
| 20 | * threaded, false if it is not. | ||
| 21 | */ | 17 | */ |
| 22 | bool is_single_threaded(struct task_struct *p) | 18 | bool current_is_single_threaded(void) |
| 23 | { | 19 | { |
| 24 | struct task_struct *g, *t; | 20 | struct task_struct *task = current; |
| 25 | struct mm_struct *mm = p->mm; | 21 | struct mm_struct *mm = task->mm; |
| 22 | struct task_struct *p, *t; | ||
| 23 | bool ret; | ||
| 26 | 24 | ||
| 27 | if (atomic_read(&p->signal->count) != 1) | 25 | if (atomic_read(&task->signal->live) != 1) |
| 28 | goto no; | 26 | return false; |
| 29 | 27 | ||
| 30 | if (atomic_read(&p->mm->mm_users) != 1) { | 28 | if (atomic_read(&mm->mm_users) == 1) |
| 31 | read_lock(&tasklist_lock); | 29 | return true; |
| 32 | do_each_thread(g, t) { | ||
| 33 | if (t->mm == mm && t != p) | ||
| 34 | goto no_unlock; | ||
| 35 | } while_each_thread(g, t); | ||
| 36 | read_unlock(&tasklist_lock); | ||
| 37 | } | ||
| 38 | 30 | ||
| 39 | return true; | 31 | ret = false; |
| 32 | rcu_read_lock(); | ||
| 33 | for_each_process(p) { | ||
| 34 | if (unlikely(p->flags & PF_KTHREAD)) | ||
| 35 | continue; | ||
| 36 | if (unlikely(p == task->group_leader)) | ||
| 37 | continue; | ||
| 38 | |||
| 39 | t = p; | ||
| 40 | do { | ||
| 41 | if (unlikely(t->mm == mm)) | ||
| 42 | goto found; | ||
| 43 | if (likely(t->mm)) | ||
| 44 | break; | ||
| 45 | /* | ||
| 46 | * t->mm == NULL. Make sure next_thread/next_task | ||
| 47 | * will see other CLONE_VM tasks which might be | ||
| 48 | * forked before exiting. | ||
| 49 | */ | ||
| 50 | smp_rmb(); | ||
| 51 | } while_each_thread(p, t); | ||
| 52 | } | ||
| 53 | ret = true; | ||
| 54 | found: | ||
| 55 | rcu_read_unlock(); | ||
| 40 | 56 | ||
| 41 | no_unlock: | 57 | return ret; |
| 42 | read_unlock(&tasklist_lock); | ||
| 43 | no: | ||
| 44 | return false; | ||
| 45 | } | 58 | } |
