416 bool SubTasksDone::valid() {
417 return _tasks != NULL;
418 }
419
420 void SubTasksDone::clear() {
421 for (uint i = 0; i < _n_tasks; i++) {
422 _tasks[i] = 0;
423 }
424 _threads_completed = 0;
425 #ifdef ASSERT
426 _claimed = 0;
427 #endif
428 }
429
430 bool SubTasksDone::try_claim_task(uint t) {
431 assert(t < _n_tasks, "bad task id.");
432 uint old = _tasks[t];
433 if (old == 0) {
434 old = Atomic::cmpxchg(1u, &_tasks[t], 0u);
435 }
436 assert(_tasks[t] == 1, "What else?");
437 bool res = old == 0;
438 #ifdef ASSERT
439 if (res) {
440 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?");
441 Atomic::inc(&_claimed);
442 }
443 #endif
444 return res;
445 }
446
447 void SubTasksDone::all_tasks_completed(uint n_threads) {
448 uint observed = _threads_completed;
449 uint old;
450 do {
451 old = observed;
452 observed = Atomic::cmpxchg(old+1, &_threads_completed, old);
453 } while (observed != old);
454 // If this was the last thread checking in, clear the tasks.
455 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads);
456 if (observed + 1 == adjusted_thread_count) {
|
416 bool SubTasksDone::valid() {
417 return _tasks != NULL;
418 }
419
420 void SubTasksDone::clear() {
421 for (uint i = 0; i < _n_tasks; i++) {
422 _tasks[i] = 0;
423 }
424 _threads_completed = 0;
425 #ifdef ASSERT
426 _claimed = 0;
427 #endif
428 }
429
430 bool SubTasksDone::try_claim_task(uint t) {
431 assert(t < _n_tasks, "bad task id.");
432 uint old = _tasks[t];
433 if (old == 0) {
434 old = Atomic::cmpxchg(1u, &_tasks[t], 0u);
435 }
436 bool res = old == 0;
437 #ifdef ASSERT
438 if (res) {
439 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?");
440 Atomic::inc(&_claimed);
441 }
442 #endif
443 return res;
444 }
445
446 void SubTasksDone::all_tasks_completed(uint n_threads) {
447 uint observed = _threads_completed;
448 uint old;
449 do {
450 old = observed;
451 observed = Atomic::cmpxchg(old+1, &_threads_completed, old);
452 } while (observed != old);
453 // If this was the last thread checking in, clear the tasks.
454 uint adjusted_thread_count = (n_threads == 0 ? 1 : n_threads);
455 if (observed + 1 == adjusted_thread_count) {
|