< prev index next >

src/hotspot/share/gc/shared/workgroup.cpp

Print this page




 147     _task    = NULL;
 148     _started = 0;
 149 
 150   }
 151 
 152   WorkData worker_wait_for_task() {
 153     // Wait for the coordinator to dispatch a task.
 154     _start_semaphore->wait();
 155 
 156     uint num_started = Atomic::add(&_started, 1u);
 157 
 158     // Subtract one to get a zero-indexed worker id.
 159     uint worker_id = num_started - 1;
 160 
 161     return WorkData(_task, worker_id);
 162   }
 163 
 164   void worker_done_with_task() {
 165     // Mark that the worker is done with the task.
 166     // The worker is not allowed to read the state variables after this line.
 167     uint not_finished = Atomic::sub(1u, &_not_finished);
 168 
 169     // The last worker signals to the coordinator that all work is completed.
 170     if (not_finished == 0) {
 171       _end_semaphore->signal();
 172     }
 173   }
 174 };
 175 
 176 class MutexGangTaskDispatcher : public GangTaskDispatcher {
 177   AbstractGangTask* _task;
 178 
 179   volatile uint _started;
 180   volatile uint _finished;
 181   volatile uint _num_workers;
 182 
 183   Monitor* _monitor;
 184 
 185  public:
 186   MutexGangTaskDispatcher() :
 187     _task(NULL),




 147     _task    = NULL;
 148     _started = 0;
 149 
 150   }
 151 
 152   WorkData worker_wait_for_task() {
 153     // Wait for the coordinator to dispatch a task.
 154     _start_semaphore->wait();
 155 
 156     uint num_started = Atomic::add(&_started, 1u);
 157 
 158     // Subtract one to get a zero-indexed worker id.
 159     uint worker_id = num_started - 1;
 160 
 161     return WorkData(_task, worker_id);
 162   }
 163 
 164   void worker_done_with_task() {
 165     // Mark that the worker is done with the task.
 166     // The worker is not allowed to read the state variables after this line.
 167     uint not_finished = Atomic::sub(&_not_finished, 1u);
 168 
 169     // The last worker signals to the coordinator that all work is completed.
 170     if (not_finished == 0) {
 171       _end_semaphore->signal();
 172     }
 173   }
 174 };
 175 
 176 class MutexGangTaskDispatcher : public GangTaskDispatcher {
 177   AbstractGangTask* _task;
 178 
 179   volatile uint _started;
 180   volatile uint _finished;
 181   volatile uint _num_workers;
 182 
 183   Monitor* _monitor;
 184 
 185  public:
 186   MutexGangTaskDispatcher() :
 187     _task(NULL),


< prev index next >