| 169 | |
| 170 | template <typename T> |
| 171 | uint64 add_task ( |
| 172 | T& obj, |
| 173 | void (T::*funct)() |
| 174 | ) |
| 175 | { |
| 176 | auto_mutex M(m); |
| 177 | const thread_id_type my_thread_id = get_thread_id(); |
| 178 | |
| 179 | // find a thread that isn't doing anything |
| 180 | long idx = find_empty_task_slot(); |
| 181 | if (idx == -1 && is_worker_thread(my_thread_id)) |
| 182 | { |
| 183 | // this function is being called from within a worker thread and there |
| 184 | // aren't any other worker threads free so just perform the task right |
| 185 | // here |
| 186 | |
| 187 | M.unlock(); |
| 188 | (obj.*funct)(); |
| 189 | |
| 190 | // return a task id that is both non-zero and also one |
| 191 | // that is never normally returned. This way calls |
| 192 | // to wait_for_task() will never block given this id. |
| 193 | return 1; |
| 194 | } |
| 195 | |
| 196 | // wait until there is a thread that isn't doing anything |
| 197 | while (idx == -1) |
| 198 | { |
| 199 | task_done_signaler.wait(); |
| 200 | idx = find_empty_task_slot(); |
| 201 | } |
| 202 | |
| 203 | tasks[idx].thread_id = my_thread_id; |
| 204 | tasks[idx].task_id = make_next_task_id(idx); |
| 205 | tasks[idx].mfp0.set(obj,funct); |
| 206 | |
| 207 | task_ready_signaler.signal(); |
| 208 | |
| 209 | return tasks[idx].task_id; |
| 210 | } |
| 211 | |
| 212 | template <typename T> |
| 213 | uint64 add_task ( |
nothing calls this directly
no test coverage detected