| 241 | } |
| 242 | |
| 243 | bool team_work(void worker(void)) |
| 244 | { int rc; |
| 245 | |
| 246 | // Current state is other threads are at wait_for_job_. |
| 247 | // This master thread (thread zero) has not completed wait_for_job_ |
| 248 | bool ok = sequential_execution_; |
| 249 | ok &= thread_number() == 0; |
| 250 | |
| 251 | // set global version of this work routine |
| 252 | worker_ = worker; |
| 253 | |
| 254 | |
| 255 | // set the new job that other threads are waiting for |
| 256 | thread_job_ = work_enum; |
| 257 | |
| 258 | // enter parallel execution soon as master thread completes wait_for_job_ |
| 259 | if( num_threads_ > 1 ) |
| 260 | sequential_execution_ = false; |
| 261 | |
| 262 | // wait until all threads have completed wait_for_job_ |
| 263 | rc = pthread_barrier_wait(&wait_for_job_); |
| 264 | ok &= (rc == 0 || rc == PTHREAD_BARRIER_SERIAL_THREAD); |
| 265 | |
| 266 | // Now do the work in this thread and then wait |
| 267 | // until all threads have completed wait_for_work_ |
| 268 | worker(); |
| 269 | rc = pthread_barrier_wait(&wait_for_work_); |
| 270 | ok &= (rc == 0 || rc == PTHREAD_BARRIER_SERIAL_THREAD); |
| 271 | |
| 272 | // Current state is other threads are at wait_for_job_. |
| 273 | // This master thread (thread zero) has not completed wait_for_job_ |
| 274 | sequential_execution_ = true; |
| 275 | |
| 276 | size_t thread_num; |
| 277 | for(thread_num = 0; thread_num < num_threads_; thread_num++) |
| 278 | ok &= thread_all_[thread_num].ok; |
| 279 | return ok; |
| 280 | } |
| 281 | |
| 282 | bool team_destroy(void) |
| 283 | { int rc; |
nothing calls this directly
no test coverage detected