diff options
| author | James Morris <jmorris@namei.org> | 2008-12-24 19:40:09 -0500 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2008-12-24 19:40:09 -0500 |
| commit | cbacc2c7f066a1e01b33b0e27ae5efbf534bc2db (patch) | |
| tree | 90d1093131d2a3543a8b3b1f3364e7c6f4081a93 /lib/is_single_threaded.c | |
| parent | 4a6908a3a050aacc9c3a2f36b276b46c0629ad91 (diff) | |
| parent | 74192246910ff4fb95309ba1a683215644beeb62 (diff) | |
Merge branch 'next' into for-linus
Diffstat (limited to 'lib/is_single_threaded.c')
| -rw-r--r-- | lib/is_single_threaded.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c new file mode 100644 index 000000000000..f1ed2fe76c65 --- /dev/null +++ b/lib/is_single_threaded.c | |||
| @@ -0,0 +1,45 @@ | |||
| 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 | */ | ||
| 12 | |||
| 13 | #include <linux/sched.h> | ||
| 14 | |||
| 15 | /** | ||
| 16 | * is_single_threaded - Determine if a thread group is single-threaded or not | ||
| 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 | */ | ||
| 22 | bool is_single_threaded(struct task_struct *p) | ||
| 23 | { | ||
| 24 | struct task_struct *g, *t; | ||
| 25 | struct mm_struct *mm = p->mm; | ||
| 26 | |||
| 27 | if (atomic_read(&p->signal->count) != 1) | ||
| 28 | goto no; | ||
| 29 | |||
| 30 | if (atomic_read(&p->mm->mm_users) != 1) { | ||
| 31 | read_lock(&tasklist_lock); | ||
| 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 | |||
| 39 | return true; | ||
| 40 | |||
| 41 | no_unlock: | ||
| 42 | read_unlock(&tasklist_lock); | ||
| 43 | no: | ||
| 44 | return false; | ||
| 45 | } | ||
