| 399 | ****************************************************************************/ |
| 400 | |
| 401 | FAR struct kwork_wqueue_s *work_queue_create(FAR const char *name, |
| 402 | int priority, |
| 403 | FAR void *stack_addr, |
| 404 | int stack_size, int nthreads) |
| 405 | { |
| 406 | FAR struct kwork_wqueue_s *wqueue; |
| 407 | int ret; |
| 408 | |
| 409 | if (nthreads < 1) |
| 410 | { |
| 411 | return NULL; |
| 412 | } |
| 413 | |
| 414 | /* Allocate a new work queue */ |
| 415 | |
| 416 | wqueue = kmm_zalloc(sizeof(struct kwork_wqueue_s) + |
| 417 | nthreads * sizeof(struct kworker_s)); |
| 418 | if (wqueue == NULL) |
| 419 | { |
| 420 | return NULL; |
| 421 | } |
| 422 | |
| 423 | /* Initialize the work queue structure */ |
| 424 | |
| 425 | list_initialize(&wqueue->expired); |
| 426 | list_initialize(&wqueue->pending); |
| 427 | wqueue->timer.func = NULL; |
| 428 | nxsem_init(&wqueue->sem, 0, 0); |
| 429 | nxsem_init(&wqueue->exsem, 0, 0); |
| 430 | wqueue->nthreads = nthreads; |
| 431 | spin_lock_init(&wqueue->lock); |
| 432 | |
| 433 | /* Create the work queue thread pool */ |
| 434 | |
| 435 | ret = work_thread_create(name, priority, stack_addr, stack_size, wqueue); |
| 436 | if (ret < 0) |
| 437 | { |
| 438 | kmm_free(wqueue); |
| 439 | return NULL; |
| 440 | } |
| 441 | |
| 442 | return wqueue; |
| 443 | } |
| 444 | |
| 445 | /**************************************************************************** |
| 446 | * Name: work_queue_free |
no test coverage detected