Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(future->state == NOT_EXECUTING)
- { /* execute it */
- // which queue is future in
- if(future->creator_id == -1)
- {
- pthread_mutex_lock(&future->pool->global_queue_lock);
- list_remove(&future->elem);
- pthread_mutex_unlock(&future->pool->global_queue_lock);
- }
- else
- {
- struct worker * worker = worker_for_id(future->creator_id);
- pthread_mutex_lock(&worker->queue_lock);
- list_remove(&future->elem);
- pthread_mutex_unlock(&worker->queue_lock);
- }
- // is current thread main or worker
- if(thread_worker == NULL)
- {
- future->state = EXECUTING;
- future->worker_id = -2;
- future->result = future->task(future->pool, future->data);
- future->state = FINISHED;
- sem_post(future->sem);
- return future->result;
- }
- else
- {
- future->state = EXECUTING;
- future->worker_id = thread_worker->worker_id;
- thread_worker->is_working = true;
- future->result = future->task(future->pool, future->data);
- future->state = FINISHED;
- thread_worker->is_working = false;
- sem_post(future->sem);
- return future->result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement