is_single_threaded.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <linux/sched.h>
  13. /**
  14. * is_single_threaded - Determine if a thread group is single-threaded or not
  15. * @p: A task in the thread group in question
  16. *
  17. * This returns true if the thread group to which a task belongs is single
  18. * threaded, false if it is not.
  19. */
  20. bool is_single_threaded(struct task_struct *p)
  21. {
  22. struct task_struct *g, *t;
  23. struct mm_struct *mm = p->mm;
  24. if (atomic_read(&p->signal->count) != 1)
  25. goto no;
  26. if (atomic_read(&p->mm->mm_users) != 1) {
  27. read_lock(&tasklist_lock);
  28. do_each_thread(g, t) {
  29. if (t->mm == mm && t != p)
  30. goto no_unlock;
  31. } while_each_thread(g, t);
  32. read_unlock(&tasklist_lock);
  33. }
  34. return true;
  35. no_unlock:
  36. read_unlock(&tasklist_lock);
  37. no:
  38. return false;
  39. }