Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1.     if(future->state == NOT_EXECUTING)
  2.     { /* execute it */
  3.  
  4.         // which queue is future in
  5.         if(future->creator_id == -1)
  6.         {
  7.             pthread_mutex_lock(&future->pool->global_queue_lock);
  8.             list_remove(&future->elem);
  9.             pthread_mutex_unlock(&future->pool->global_queue_lock);
  10.         }
  11.         else
  12.         {
  13.             struct worker * worker = worker_for_id(future->creator_id);
  14.             pthread_mutex_lock(&worker->queue_lock);
  15.             list_remove(&future->elem);
  16.             pthread_mutex_unlock(&worker->queue_lock);         
  17.         }
  18.        
  19.         // is current thread main or worker
  20.         if(thread_worker == NULL)
  21.         {
  22.             future->state = EXECUTING;
  23.             future->worker_id = -2;
  24.             future->result = future->task(future->pool, future->data);     
  25.             future->state = FINISHED;
  26.             sem_post(future->sem);     
  27.             return future->result;
  28.         }
  29.         else
  30.         {
  31.             future->state = EXECUTING;
  32.             future->worker_id = thread_worker->worker_id;
  33.             thread_worker->is_working = true;
  34.             future->result = future->task(future->pool, future->data);
  35.             future->state = FINISHED;
  36.             thread_worker->is_working = false;     
  37.             sem_post(future->sem);     
  38.             return future->result;         
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement