Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 157313
b: refs/heads/master
c: d2e3ee9
h: refs/heads/master
i:
  157311: a73562f
v: v3
  • Loading branch information
Oleg Nesterov authored and James Morris committed Jul 16, 2009
1 parent 6821afe commit 0636083
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 713c0ecdb888e9ef6f085e828555455c5916b07f
refs/heads/master: d2e3ee9b29f5de5b01e611b04e6fb29760589b01
62 changes: 36 additions & 26 deletions trunk/lib/is_single_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,44 @@

#include <linux/sched.h>

/**
* is_single_threaded - Determine if a thread group is single-threaded or not
* @p: A task in the thread group in question
*
* This returns true if the thread group to which a task belongs is single
* threaded, false if it is not.
/*
* Returns true if the task does not share ->mm with another thread/process.
*/
bool is_single_threaded(struct task_struct *p)
bool is_single_threaded(struct task_struct *task)
{
struct task_struct *g, *t;
struct mm_struct *mm = p->mm;

if (atomic_read(&p->signal->count) != 1)
goto no;

if (atomic_read(&p->mm->mm_users) != 1) {
read_lock(&tasklist_lock);
do_each_thread(g, t) {
if (t->mm == mm && t != p)
goto no_unlock;
} while_each_thread(g, t);
read_unlock(&tasklist_lock);
}
struct mm_struct *mm = task->mm;
struct task_struct *p, *t;
bool ret;

might_sleep();

if (atomic_read(&task->signal->live) != 1)
return false;

return true;
if (atomic_read(&mm->mm_users) == 1)
return true;

ret = false;
down_write(&mm->mmap_sem);
rcu_read_lock();
for_each_process(p) {
if (unlikely(p->flags & PF_KTHREAD))
continue;
if (unlikely(p == task->group_leader))
continue;

t = p;
do {
if (unlikely(t->mm == mm))
goto found;
if (likely(t->mm))
break;
} while_each_thread(p, t);
}
ret = true;
found:
rcu_read_unlock();
up_write(&mm->mmap_sem);

no_unlock:
read_unlock(&tasklist_lock);
no:
return false;
return ret;
}

0 comments on commit 0636083

Please sign in to comment.