kthread.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef _LINUX_KTHREAD_H
  2. #define _LINUX_KTHREAD_H
  3. /* Simple interface for creating and stopping kernel threads without mess. */
  4. #include <linux/err.h>
  5. #include <linux/sched.h>
  6. struct task_struct *kthread_create(int (*threadfn)(void *data),
  7. void *data,
  8. const char namefmt[], ...)
  9. __attribute__((format(printf, 3, 4)));
  10. /**
  11. * kthread_run - create and wake a thread.
  12. * @threadfn: the function to run until signal_pending(current).
  13. * @data: data ptr for @threadfn.
  14. * @namefmt: printf-style name for the thread.
  15. *
  16. * Description: Convenient wrapper for kthread_create() followed by
  17. * wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
  18. */
  19. #define kthread_run(threadfn, data, namefmt, ...) \
  20. ({ \
  21. struct task_struct *__k \
  22. = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
  23. if (!IS_ERR(__k)) \
  24. wake_up_process(__k); \
  25. __k; \
  26. })
  27. void kthread_bind(struct task_struct *k, unsigned int cpu);
  28. int kthread_stop(struct task_struct *k);
  29. int kthread_should_stop(void);
  30. int kthreadd(void *unused);
  31. extern struct task_struct *kthreadd_task;
  32. #endif /* _LINUX_KTHREAD_H */