MCPcopy Create free account
hub / github.com/apache/nuttx / work_thread_create

Function work_thread_create

sched/wqueue/kwork_thread.c:301–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299 ****************************************************************************/
300
301static int work_thread_create(FAR const char *name, int priority,
302 FAR void *stack_addr, int stack_size,
303 FAR struct kwork_wqueue_s *wqueue)
304{
305 FAR struct kworker_s *worker = wq_get_worker(wqueue);
306 FAR char *argv[3];
307 char arg0[32];
308 char arg1[32];
309 int wndx;
310 int pid;
311 FAR void *stack = NULL;
312
313 /* Don't permit any of the threads to run until we have fully initialized
314 * all of them.
315 */
316
317 sched_lock();
318
319 for (wndx = 0; wndx < wqueue->nthreads; wndx++)
320 {
321 nxsem_init(&worker[wndx].wait, 0, 0);
322
323 snprintf(arg0, sizeof(arg0), "%p", wqueue);
324 snprintf(arg1, sizeof(arg1), "%p", &worker[wndx]);
325 argv[0] = arg0;
326 argv[1] = arg1;
327 argv[2] = NULL;
328
329 /* In case of the stack_addr is NULL */
330
331 if (stack_addr)
332 {
333 stack = (FAR void *)((uintptr_t)stack_addr + wndx * stack_size);
334 }
335
336 pid = kthread_create_with_stack(name, priority, stack,
337 stack_size, work_thread, argv);
338
339 DEBUGASSERT(pid > 0);
340 if (pid < 0)
341 {
342 serr("ERROR: work_thread_create %d failed: %d\n", wndx, pid);
343 sched_unlock();
344 return pid;
345 }
346
347 worker[wndx].pid = pid;
348 }
349
350 sched_unlock();
351 return OK;
352}
353
354/****************************************************************************
355 * Public Functions

Callers 3

work_queue_createFunction · 0.85
work_start_highpriFunction · 0.85
work_start_lowpriFunction · 0.85

Calls 5

sched_lockFunction · 0.85
nxsem_initFunction · 0.85
sched_unlockFunction · 0.85
snprintfFunction · 0.50

Tested by

no test coverage detected