136 _task = task;
137 _not_finished = num_workers;
138
139 // Dispatch 'num_workers' number of tasks.
140 _start_semaphore->signal(num_workers);
141
142 // Wait for the last worker to signal the coordinator.
143 _end_semaphore->wait();
144
145 // No workers are allowed to read the state variables after the coordinator has been signaled.
146 assert(_not_finished == 0, "%d not finished workers?", _not_finished);
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(1u, &_started);
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 {
|
136 _task = task;
137 _not_finished = num_workers;
138
139 // Dispatch 'num_workers' number of tasks.
140 _start_semaphore->signal(num_workers);
141
142 // Wait for the last worker to signal the coordinator.
143 _end_semaphore->wait();
144
145 // No workers are allowed to read the state variables after the coordinator has been signaled.
146 assert(_not_finished == 0, "%d not finished workers?", _not_finished);
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 {
|