equal
deleted
inserted
replaced
432 } |
432 } |
433 |
433 |
434 // SubTasksDone functions. |
434 // SubTasksDone functions. |
435 |
435 |
436 SubTasksDone::SubTasksDone(uint n) : |
436 SubTasksDone::SubTasksDone(uint n) : |
437 _n_tasks(n), _n_threads(1), _tasks(NULL) { |
437 _n_tasks(n), _tasks(NULL) { |
438 _tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal); |
438 _tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal); |
439 guarantee(_tasks != NULL, "alloc failure"); |
439 guarantee(_tasks != NULL, "alloc failure"); |
440 clear(); |
440 clear(); |
441 } |
441 } |
442 |
442 |
443 bool SubTasksDone::valid() { |
443 bool SubTasksDone::valid() { |
444 return _tasks != NULL; |
444 return _tasks != NULL; |
445 } |
|
446 |
|
447 void SubTasksDone::set_n_threads(uint t) { |
|
448 assert(_claimed == 0 || _threads_completed == _n_threads, |
|
449 "should not be called while tasks are being processed!"); |
|
450 _n_threads = (t == 0 ? 1 : t); |
|
451 } |
445 } |
452 |
446 |
453 void SubTasksDone::clear() { |
447 void SubTasksDone::clear() { |
454 for (uint i = 0; i < _n_tasks; i++) { |
448 for (uint i = 0; i < _n_tasks; i++) { |
455 _tasks[i] = 0; |
449 _tasks[i] = 0; |
475 } |
469 } |
476 #endif |
470 #endif |
477 return res; |
471 return res; |
478 } |
472 } |
479 |
473 |
480 void SubTasksDone::all_tasks_completed() { |
474 void SubTasksDone::all_tasks_completed(uint n_threads) { |
481 jint observed = _threads_completed; |
475 jint observed = _threads_completed; |
482 jint old; |
476 jint old; |
483 do { |
477 do { |
484 old = observed; |
478 old = observed; |
485 observed = Atomic::cmpxchg(old+1, &_threads_completed, old); |
479 observed = Atomic::cmpxchg(old+1, &_threads_completed, old); |
486 } while (observed != old); |
480 } while (observed != old); |
487 // If this was the last thread checking in, clear the tasks. |
481 // If this was the last thread checking in, clear the tasks. |
488 if (observed+1 == (jint)_n_threads) clear(); |
482 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads); |
|
483 if (observed + 1 == (jint)adjusted_thread_count) { |
|
484 clear(); |
|
485 } |
489 } |
486 } |
490 |
487 |
491 |
488 |
492 SubTasksDone::~SubTasksDone() { |
489 SubTasksDone::~SubTasksDone() { |
493 if (_tasks != NULL) FREE_C_HEAP_ARRAY(jint, _tasks); |
490 if (_tasks != NULL) FREE_C_HEAP_ARRAY(jint, _tasks); |