aboutsummaryrefslogtreecommitdiffstats
path: root/include/sys/thread.h
diff options
context:
space:
mode:
authorTim Chase <[email protected]>2014-03-26 08:29:24 -0500
committerBrian Behlendorf <[email protected]>2014-04-08 12:44:42 -0700
commit17a527cb0f44cef6582583e502621541061d8817 (patch)
tree5619e8f29e0272ef6206ffa788061bdccc47d971 /include/sys/thread.h
parente19101e08f25708b03e5ff98a4da5756cfd709f7 (diff)
Support post-3.13 kthread_create() semantics.
Provide spl_kthread_create() as a wrapper to the kernel's kthread_create() to provide pre-3.13 semantics. Re-try if the call is interrupted or if it would have returned -ENOMEM. Otherwise return NULL. Signed-off-by: Chunwei Chen <[email protected]> Signed-off-by: Tim Chase <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #339
Diffstat (limited to 'include/sys/thread.h')
-rw-r--r--include/sys/thread.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/sys/thread.h b/include/sys/thread.h
index 864a74bba..f6c197255 100644
--- a/include/sys/thread.h
+++ b/include/sys/thread.h
@@ -60,4 +60,32 @@ extern kthread_t *__thread_create(caddr_t stk, size_t stksize,
int state, pri_t pri);
extern void __thread_exit(void);
+/*
+ * spl_kthread_create - Wrapper providing pre-3.13 semantics for
+ * kthread_create() in which it is not killable and less likely
+ * to return -ENOMEM.
+ */
+static inline struct task_struct *
+spl_kthread_create(int (*func)(void *), void *data, const char namefmt[], ...)
+{
+ struct task_struct *tsk;
+ va_list args;
+
+ va_start(args, namefmt);
+ do {
+ tsk = kthread_create_on_node(func, data,
+ -1, namefmt, args);
+ if (IS_ERR(tsk)) {
+ if (signal_pending(current)) {
+ clear_thread_flag(TIF_SIGPENDING);
+ continue;
+ }
+ if (PTR_ERR(tsk) == -ENOMEM)
+ continue;
+ return (NULL);
+ } else
+ return (tsk);
+ } while (1);
+}
+
#endif /* _SPL_THREAD_H */