utils/worker.c
/**
 * worker_enqueue - enqueue a work structure in the specified worker
 *
 * @worker_id: the id of the worker threadd
 * @work: the work structure
 *
 * 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.
 */
enqueue a work structure in the specified worker
@worker_id: the id of the worker threadd
@work: the work structure

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.
enqueue a work structure in the specified worker @worker_id : the id of the worker threadd @work : the work structure 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_enqueue(int worker_id, worker_cb_t *work)
{
  sem_wait(&g_lock_system_workers);
  worker_t *worker = worker_get(worker_id);
  if (worker == NULL) {
    sem_post(&g_lock_system_workers);
    return -EINVAL;
  }
  sem_post(&g_lock_system_workers);
  worker_cb_t *work_copy = calloc(1, sizeof(worker_cb_t));
  if (work_copy == NULL) {
    return -ENOMEM;
  }
  memcpy(work_copy, work, sizeof(worker_cb_t));
  sem_wait(&worker->g_lock_worker_list);
  struct list_head *pos, *temp;
  list_for_each_safe(pos, temp, &worker->worker_cb) {
    worker_cb_t *current_work = container_of(pos, worker_cb_t, work_list);
    if (current_work->wake_ms > work_copy->wake_ms) {
      list_del(pos);
      list_add(&work_copy->work_list, &worker->worker_cb);
      list_add(pos, &worker->worker_cb);
      sem_post(&worker->g_lock_worker_list);
      return 0;
    }
  }
  list_add(&work_copy->work_list, &worker->worker_cb);
  sem_post(&worker->g_lock_worker_list);
  return 0;
}
int worker_enqueue ( int worker_id , worker_cb_t * work ) { sem_wait ( & g_lock_system_workers ) ; worker_t * worker = worker_get ( worker_id ) ; if ( worker == NULL ) { sem_post ( & g_lock_system_workers ) ; return - EINVAL ; } sem_post ( & g_lock_system_workers ) ; worker_cb_t * work_copy = calloc ( 1 , sizeof ( worker_cb_t ) ) ; if ( work_copy == NULL ) { return - ENOMEM ; } memcpy ( work_copy , work , sizeof ( worker_cb_t ) ) ; sem_wait ( & worker -> g_lock_worker_list ) ; struct list_head * pos , * temp ; list_for_each_safe ( pos , temp , & worker -> worker_cb ) { worker_cb_t * current_work = container_of ( pos , worker_cb_t , work_list ) ; if ( current_work -> wake_ms > work_copy -> wake_ms ) { list_del ( pos ) ; list_add ( & work_copy -> work_list , & worker -> worker_cb ) ; list_add ( pos , & worker -> worker_cb ) ; sem_post ( & worker -> g_lock_worker_list ) ; return 0 ; } } list_add ( & work_copy -> work_list , & worker -> worker_cb ) ; sem_post ( & worker -> g_lock_worker_list ) ; return 0 ; }
worker_enqueue - enqueue a work structure in the specified worker
 @worker_id: the id of the worker threadd
 @work: the work structure
worker_enqueue - enqueue a work structure in the specified worker @worker_id : the id of the worker threadd @work : the work structure
/* Get the system worker from the worker_id */ /* Create a copy of the object */ /* Find a place where to insert the work item */ /* Work that need to be done first is placed at the beggining of the list
     */