utils/worker.c
/**
 * worker_create - create a new worker thread with the specified priorityd
 *
 * @priority: the prioroty of the threadd
 * @name: friendly name of the worker thread
 *
 * Create a new worker thread and return the handle to the worker thread on
 * success.
 *
 * Assumption: priority is ignored if the scheduler is FIFO without priority
 * scheduling.
 */
create a new worker thread with the specified priorityd
@priority: the prioroty of the threadd
@name: friendly name of the worker thread

Create a new worker thread and return the handle to the worker thread on
success.

priority is ignored if the scheduler is FIFO without priority
scheduling.
create a new worker thread with the specified priorityd @priority : the prioroty of the threadd @name : friendly name of the worker thread Create a new worker thread and return the handle to the worker thread on success . priority is ignored if the scheduler is FIFO without priority scheduling .
int worker_create(int priority, const char *name)
{
  worker_t *new_worker = calloc(1, sizeof(worker_t));
  if (new_worker == NULL) {
    return -ENOMEM;
  }
  sem_init(&new_worker->g_lock_worker_list, 0, 0);
  sem_init(&new_worker->shutdown_notify, 0, 0);
  new_worker->is_running_enabled = true;
  int ret = sched_create_task(worker_main,
                              CONFIG_WORKER_STACK_SIZE,
                              1,
                              (char **)new_worker,
                              "Worker");
  if (ret != 0) {
    ret = -EINVAL;
    goto free_with_worker;
  }
  sem_wait(&g_lock_system_workers);
  new_worker->workqueue_id = g_uid_counter;
  if (g_uid_counter == INT_MAX) {
    ret = -ENOSPC;
    sem_post(&g_lock_system_workers);
    goto free_with_task;
  }
  g_uid_counter++;
  list_add(&new_worker->worker_cb, &g_system_workers);
  sem_post(&g_lock_system_workers);
  return new_worker->workqueue_id;
free_with_task:
  new_worker->is_running_enabled = false;
free_with_worker:
  free(new_worker);
  return ret;
}
int worker_create ( int priority , const char * name ) { worker_t * new_worker = calloc ( 1 , sizeof ( worker_t ) ) ; if ( new_worker == NULL ) { return - ENOMEM ; } sem_init ( & new_worker -> g_lock_worker_list , 0 , 0 ) ; sem_init ( & new_worker -> shutdown_notify , 0 , 0 ) ; new_worker -> is_running_enabled = true ; int ret = sched_create_task ( worker_main , CONFIG_WORKER_STACK_SIZE , 1 , ( char * * ) new_worker , " " ) ; if ( ret != 0 ) { ret = - EINVAL ; goto free_with_worker ; } sem_wait ( & g_lock_system_workers ) ; new_worker -> workqueue_id = g_uid_counter ; if ( g_uid_counter == INT_MAX ) { ret = - ENOSPC ; sem_post ( & g_lock_system_workers ) ; goto free_with_task ; } g_uid_counter ++ ; list_add ( & new_worker -> worker_cb , & g_system_workers ) ; sem_post ( & g_lock_system_workers ) ; return new_worker -> workqueue_id ; free_with_task : new_worker -> is_running_enabled = false ; free_with_worker : free ( new_worker ) ; return ret ; }
worker_create - create a new worker thread with the specified priorityd
 @priority: the prioroty of the threadd
 @name: friendly name of the worker thread
worker_create - create a new worker thread with the specified priorityd @priority : the prioroty of the threadd @name : friendly name of the worker thread