utils/worker.c
/**
 * worker_destroy - destroy a worker with all the associated resources
 *
 * @worker_id: the id of the worker threadd
 *
 * Cancels a job that was enqueued on a worker thread. This function does not
 * guarantee that the cancellation will occur because a work item can be 
 * scheduled to run by the time we call this function.
 *
 */
destroy a worker with all the associated resources
@worker_id: the id of the worker threadd

Cancels a job that was enqueued on a worker thread. This function does not
guarantee that the cancellation will occur because a work item can be
scheduled to run by the time we call this function.
destroy a worker with all the associated resources @worker_id : the id of the worker threadd Cancels a job that was enqueued on a worker thread . This function does not guarantee that the cancellation will occur because a work item can be scheduled to run by the time we call this function .
int worker_destroy(int worker_id)
{
  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->is_running_enabled = false;
  sem_wait(&worker->shutdown_notify);
  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);
    list_del(pos);
    if (current_work->cleanup_cb) {
      current_work->cleanup_cb(current_work->priv_arg);
    }
    free(current_work);
  }
  return 0;
}
int worker_destroy ( int worker_id ) { 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 -> is_running_enabled = false ; sem_wait ( & worker -> shutdown_notify ) ; 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 ) ; list_del ( pos ) ; if ( current_work -> cleanup_cb ) { current_work -> cleanup_cb ( current_work -> priv_arg ) ; } free ( current_work ) ; } return 0 ; }
worker_destroy - destroy a worker with all the associated resources
 @worker_id: the id of the worker threadd
worker_destroy - destroy a worker with all the associated resources @worker_id : the id of the worker threadd
/* Get the system worker from the worker_id */ /* Shutdown the worker task */ /* Free the resources - CAUTIO
   *
   * If there are work items that have arguments allocated on the heap
   * freeing the work item may cause leaking the arguments if no cleanup
   * callback was assigned to the work item.
   */