MCPcopy Create free account
hub / github.com/F-Stack/f-stack / __thread_create

Function __thread_create

freebsd/contrib/openzfs/module/os/linux/spl/spl-thread.c:79–127  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

77 * style callers likely never check for... since it can't fail.
78 */
79kthread_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}
128EXPORT_SYMBOL(__thread_create);
129
130/*

Callers

nothing calls this directly

Calls 6

strncpyFunction · 0.85
strstrFunction · 0.85
spl_kthread_createFunction · 0.85
IS_ERRFunction · 0.85
wake_up_processFunction · 0.85
kmem_freeFunction · 0.50

Tested by

no test coverage detected