* thread_create() may block forever if it cannot create a thread or * allocate memory. This is preferable to returning a NULL which Solaris * style callers likely never check for... since it can't fail. */
| 77 | * style callers likely never check for... since it can't fail. |
| 78 | */ |
| 79 | kthread_t * |
| 80 | __thread_create(caddr_t stk, size_t stksize, thread_func_t func, |
| 81 | const char *name, void *args, size_t len, proc_t *pp, int state, pri_t pri) |
| 82 | { |
| 83 | thread_priv_t *tp; |
| 84 | struct task_struct *tsk; |
| 85 | char *p; |
| 86 | |
| 87 | /* Option pp is simply ignored */ |
| 88 | /* Variable stack size unsupported */ |
| 89 | ASSERT(stk == NULL); |
| 90 | |
| 91 | tp = kmem_alloc(sizeof (thread_priv_t), KM_PUSHPAGE); |
| 92 | if (tp == NULL) |
| 93 | return (NULL); |
| 94 | |
| 95 | tp->tp_magic = TP_MAGIC; |
| 96 | tp->tp_name_size = strlen(name) + 1; |
| 97 | |
| 98 | tp->tp_name = kmem_alloc(tp->tp_name_size, KM_PUSHPAGE); |
| 99 | if (tp->tp_name == NULL) { |
| 100 | kmem_free(tp, sizeof (thread_priv_t)); |
| 101 | return (NULL); |
| 102 | } |
| 103 | |
| 104 | strncpy(tp->tp_name, name, tp->tp_name_size); |
| 105 | |
| 106 | /* |
| 107 | * Strip trailing "_thread" from passed name which will be the func |
| 108 | * name since the exposed API has no parameter for passing a name. |
| 109 | */ |
| 110 | p = strstr(tp->tp_name, "_thread"); |
| 111 | if (p) |
| 112 | p[0] = '\0'; |
| 113 | |
| 114 | tp->tp_func = func; |
| 115 | tp->tp_args = args; |
| 116 | tp->tp_len = len; |
| 117 | tp->tp_state = state; |
| 118 | tp->tp_pri = pri; |
| 119 | |
| 120 | tsk = spl_kthread_create(thread_generic_wrapper, (void *)tp, |
| 121 | "%s", tp->tp_name); |
| 122 | if (IS_ERR(tsk)) |
| 123 | return (NULL); |
| 124 | |
| 125 | wake_up_process(tsk); |
| 126 | return ((kthread_t *)tsk); |
| 127 | } |
| 128 | EXPORT_SYMBOL(__thread_create); |
| 129 | |
| 130 | /* |
nothing calls this directly
no test coverage detected