123 _end_semaphore(new Semaphore())
124 { }
125
126 ~SemaphoreGangTaskDispatcher() {
127 delete _start_semaphore;
128 delete _end_semaphore;
129 }
130
131 void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) {
132 // No workers are allowed to read the state variables until they have been signaled.
133 _task = task;
134 _not_finished = num_workers;
135
136 // Dispatch 'num_workers' number of tasks.
137 _start_semaphore->signal(num_workers);
138
139 // Wait for the last worker to signal the coordinator.
140 _end_semaphore->wait();
141
142 // No workers are allowed to read the state variables after the coordinator has been signaled.
143 assert(_not_finished == 0, err_msg("%d not finished workers?", _not_finished));
144 _task = NULL;
145 _started = 0;
146
147 }
148
149 WorkData worker_wait_for_task() {
150 // Wait for the coordinator to dispatch a task.
151 _start_semaphore->wait();
152
153 uint num_started = (uint) Atomic::add(1, (volatile jint*)&_started);
154
155 // Subtract one to get a zero-indexed worker id.
156 uint worker_id = num_started - 1;
157
158 return WorkData(_task, worker_id);
159 }
160
161 void worker_done_with_task() {
162 // Mark that the worker is done with the task.
163 // The worker is not allowed to read the state variables after this line.
|
123 _end_semaphore(new Semaphore())
124 { }
125
126 ~SemaphoreGangTaskDispatcher() {
127 delete _start_semaphore;
128 delete _end_semaphore;
129 }
130
131 void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) {
132 // No workers are allowed to read the state variables until they have been signaled.
133 _task = task;
134 _not_finished = num_workers;
135
136 // Dispatch 'num_workers' number of tasks.
137 _start_semaphore->signal(num_workers);
138
139 // Wait for the last worker to signal the coordinator.
140 _end_semaphore->wait();
141
142 // No workers are allowed to read the state variables after the coordinator has been signaled.
143 assert(_not_finished == 0, "%d not finished workers?", _not_finished);
144 _task = NULL;
145 _started = 0;
146
147 }
148
149 WorkData worker_wait_for_task() {
150 // Wait for the coordinator to dispatch a task.
151 _start_semaphore->wait();
152
153 uint num_started = (uint) Atomic::add(1, (volatile jint*)&_started);
154
155 // Subtract one to get a zero-indexed worker id.
156 uint worker_id = num_started - 1;
157
158 return WorkData(_task, worker_id);
159 }
160
161 void worker_done_with_task() {
162 // Mark that the worker is done with the task.
163 // The worker is not allowed to read the state variables after this line.
|