| 165 | // ---------------------------------------------------------------------------------------- |
| 166 | |
| 167 | void thread_pool_implementation:: |
| 168 | thread ( |
| 169 | ) |
| 170 | { |
| 171 | { |
| 172 | // save the id of this worker thread into worker_thread_ids |
| 173 | auto_mutex M(m); |
| 174 | thread_id_type id = get_thread_id(); |
| 175 | worker_thread_ids.push_back(id); |
| 176 | } |
| 177 | |
| 178 | task_state_type task; |
| 179 | while (we_are_destructing == false) |
| 180 | { |
| 181 | long idx = 0; |
| 182 | |
| 183 | // wait for a task to do |
| 184 | { auto_mutex M(m); |
| 185 | while ( (idx = find_ready_task()) == -1 && we_are_destructing == false) |
| 186 | task_ready_signaler.wait(); |
| 187 | |
| 188 | if (we_are_destructing) |
| 189 | break; |
| 190 | |
| 191 | tasks[idx].is_being_processed = true; |
| 192 | task = tasks[idx]; |
| 193 | } |
| 194 | |
| 195 | std::exception_ptr eptr = nullptr; |
| 196 | try |
| 197 | { |
| 198 | // now do the task |
| 199 | if (task.bfp) |
| 200 | task.bfp(); |
| 201 | else if (task.mfp0) |
| 202 | task.mfp0(); |
| 203 | else if (task.mfp1) |
| 204 | task.mfp1(task.arg1); |
| 205 | else if (task.mfp2) |
| 206 | task.mfp2(task.arg1, task.arg2); |
| 207 | } |
| 208 | catch(...) |
| 209 | { |
| 210 | eptr = std::current_exception(); |
| 211 | } |
| 212 | |
| 213 | // Now let others know that we finished the task. We do this |
| 214 | // by clearing out the state of this task |
| 215 | { auto_mutex M(m); |
| 216 | tasks[idx].is_being_processed = false; |
| 217 | tasks[idx].task_id = 0; |
| 218 | tasks[idx].bfp.clear(); |
| 219 | tasks[idx].mfp0.clear(); |
| 220 | tasks[idx].mfp1.clear(); |
| 221 | tasks[idx].mfp2.clear(); |
| 222 | tasks[idx].arg1 = 0; |
| 223 | tasks[idx].arg2 = 0; |
| 224 | tasks[idx].eptr = eptr; |
nothing calls this directly
no test coverage detected