| 171 | } |
| 172 | |
| 173 | bool team_work(void worker(void)) |
| 174 | { |
| 175 | // Current state is other threads are at wait_for_job_. |
| 176 | // This master thread (thread zero) has not completed wait_for_job_ |
| 177 | bool ok = sequential_execution_; |
| 178 | ok &= thread_number() == 0; |
| 179 | ok &= wait_for_work_ != nullptr; |
| 180 | ok &= wait_for_job_ != nullptr; |
| 181 | |
| 182 | // set global version of this work routine |
| 183 | worker_ = worker; |
| 184 | |
| 185 | // set the new job that other threads are waiting for |
| 186 | thread_job_ = work_enum; |
| 187 | |
| 188 | // Enter parallel execution when master thread calls wait_for_job_ |
| 189 | if( num_threads_ > 1 ) |
| 190 | sequential_execution_ = false; |
| 191 | wait_for_job_->wait(); |
| 192 | |
| 193 | // Now do the work in this thread and then wait |
| 194 | // until all threads have completed wait_for_work_ |
| 195 | worker(); |
| 196 | wait_for_work_->wait(); |
| 197 | |
| 198 | // Current state is other threads are at wait_for_job_. |
| 199 | // This master thread (thread zero) has not completed wait_for_job_ |
| 200 | sequential_execution_ = true; |
| 201 | |
| 202 | size_t thread_num; |
| 203 | for(thread_num = 0; thread_num < num_threads_; thread_num++) |
| 204 | ok &= thread_all_[thread_num].ok; |
| 205 | return ok; |
| 206 | } |
| 207 | |
| 208 | bool team_destroy(void) |
| 209 | { // Current state is other threads are at wait_for_job_. |
nothing calls this directly
no test coverage detected