494 for (int i = 0; i < n; i++) { |
494 for (int i = 0; i < n; i++) { |
495 _queues[i] = NULL; |
495 _queues[i] = NULL; |
496 } |
496 } |
497 } |
497 } |
498 |
498 |
499 bool steal_1_random(uint queue_num, int* seed, E& t); |
|
500 bool steal_best_of_2(uint queue_num, int* seed, E& t); |
499 bool steal_best_of_2(uint queue_num, int* seed, E& t); |
501 bool steal_best_of_all(uint queue_num, int* seed, E& t); |
|
502 |
500 |
503 void register_queue(uint i, T* q); |
501 void register_queue(uint i, T* q); |
504 |
502 |
505 T* queue(uint n); |
503 T* queue(uint n); |
506 |
504 |
533 return true; |
531 return true; |
534 } |
532 } |
535 } |
533 } |
536 TASKQUEUE_STATS_ONLY(queue(queue_num)->stats.record_steal(false)); |
534 TASKQUEUE_STATS_ONLY(queue(queue_num)->stats.record_steal(false)); |
537 return false; |
535 return false; |
538 } |
|
539 |
|
540 template<class T, MEMFLAGS F> bool |
|
541 GenericTaskQueueSet<T, F>::steal_best_of_all(uint queue_num, int* seed, E& t) { |
|
542 if (_n > 2) { |
|
543 int best_k; |
|
544 uint best_sz = 0; |
|
545 for (uint k = 0; k < _n; k++) { |
|
546 if (k == queue_num) continue; |
|
547 uint sz = _queues[k]->size(); |
|
548 if (sz > best_sz) { |
|
549 best_sz = sz; |
|
550 best_k = k; |
|
551 } |
|
552 } |
|
553 return best_sz > 0 && _queues[best_k]->pop_global(t); |
|
554 } else if (_n == 2) { |
|
555 // Just try the other one. |
|
556 int k = (queue_num + 1) % 2; |
|
557 return _queues[k]->pop_global(t); |
|
558 } else { |
|
559 assert(_n == 1, "can't be zero."); |
|
560 return false; |
|
561 } |
|
562 } |
|
563 |
|
564 template<class T, MEMFLAGS F> bool |
|
565 GenericTaskQueueSet<T, F>::steal_1_random(uint queue_num, int* seed, E& t) { |
|
566 if (_n > 2) { |
|
567 uint k = queue_num; |
|
568 while (k == queue_num) k = TaskQueueSetSuper::randomParkAndMiller(seed) % _n; |
|
569 return _queues[2]->pop_global(t); |
|
570 } else if (_n == 2) { |
|
571 // Just try the other one. |
|
572 int k = (queue_num + 1) % 2; |
|
573 return _queues[k]->pop_global(t); |
|
574 } else { |
|
575 assert(_n == 1, "can't be zero."); |
|
576 return false; |
|
577 } |
|
578 } |
536 } |
579 |
537 |
580 template<class T, MEMFLAGS F> bool |
538 template<class T, MEMFLAGS F> bool |
581 GenericTaskQueueSet<T, F>::steal_best_of_2(uint queue_num, int* seed, E& t) { |
539 GenericTaskQueueSet<T, F>::steal_best_of_2(uint queue_num, int* seed, E& t) { |
582 if (_n > 2) { |
540 if (_n > 2) { |