utils/worker.c
/**
 * worker_cancel_work - cancel work that was enqueued on a worker threadr
 *
 * @worker_id: the id of the worker threadd
 * @job_uid: the job that we wish to cancele
 *
 * 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.
 *
 * Returns 0(OK) in case the job was cancelled otherwise -EINVAL.
 */
cancel work that was enqueued on a worker threadr
@worker_id: the id of the worker threadd
@job_uid: the job that we wish to cancele

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.

Returns 0(OK) in case the job was cancelled otherwise -EINVAL.
cancel work that was enqueued on a worker threadr @worker_id : the id of the worker threadd @job_uid : the job that we wish to cancele 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 . Returns 0 ( OK ) in case the job was cancelled otherwise - EINVAL .
int worker_cancel_work(int worker_id, int job_uid)
{
  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);
  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->work_uid == job_uid) {
      list_del(pos);
      if (current_work->cleanup_cb) {
        current_work->cleanup_cb(current_work->priv_arg);
      }
      free(current_work);
      sem_post(&worker->g_lock_worker_list);
      return 0;
    }
  }
  sem_post(&worker->g_lock_worker_list);
  return -EINVAL;
}
int worker_cancel_work ( int worker_id , int job_uid ) { 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 ) ; 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 -> work_uid == job_uid ) { list_del ( pos ) ; if ( current_work -> cleanup_cb ) { current_work -> cleanup_cb ( current_work -> priv_arg ) ; } free ( current_work ) ; sem_post ( & worker -> g_lock_worker_list ) ; return 0 ; } } sem_post ( & worker -> g_lock_worker_list ) ; return - EINVAL ; }
worker_cancel_work - cancel work that was enqueued on a worker threadr
 @worker_id: the id of the worker threadd
 @job_uid: the job that we wish to cancele
worker_cancel_work - cancel work that was enqueued on a worker threadr @worker_id : the id of the worker threadd @job_uid : the job that we wish to cancele
/* Get the system worker from the worker_id */ /* If we found the job unique identifier call the clean up callback
     * remove the work item from the list and free the work item.
     */