| 220 | // ------------------------------------------------------------------------------------ |
| 221 | |
| 222 | void thread_starter ( |
| 223 | void* object |
| 224 | ) |
| 225 | { |
| 226 | // get a reference to the calling threader object |
| 227 | threader& self = *static_cast<threader*>(object); |
| 228 | |
| 229 | |
| 230 | { |
| 231 | auto_mutex M(self.data_mutex); |
| 232 | |
| 233 | // add this thread id |
| 234 | thread_id_type thread_id = get_thread_id(); |
| 235 | self.thread_ids.add(thread_id); |
| 236 | |
| 237 | // indicate that this thread is now in the thread pool |
| 238 | ++self.pool_count; |
| 239 | |
| 240 | while (self.destruct == false) |
| 241 | { |
| 242 | // if data is ready then process it and launch the thread |
| 243 | // if its not ready then go back into the pool |
| 244 | while (self.function_pointer != 0) |
| 245 | { |
| 246 | // indicate that this thread is now out of the thread pool |
| 247 | --self.pool_count; |
| 248 | |
| 249 | // get the data for the function call |
| 250 | void (*funct)(void*) = self.function_pointer; |
| 251 | void* param = self.parameter; |
| 252 | self.function_pointer = 0; |
| 253 | |
| 254 | // signal that the data is now empty |
| 255 | self.data_empty.signal(); |
| 256 | |
| 257 | self.data_mutex.unlock(); |
| 258 | // Call funct with its intended parameter. If this function throws then |
| 259 | // we intentionally let the exception escape the thread and result in whatever |
| 260 | // happens when it gets caught by the OS (generally the program is terminated). |
| 261 | funct(param); |
| 262 | self.call_end_handlers(); |
| 263 | |
| 264 | self.data_mutex.lock(); |
| 265 | |
| 266 | // indicate that this thread is now back in the thread pool |
| 267 | ++self.pool_count; |
| 268 | } |
| 269 | |
| 270 | if (self.destruct == true) |
| 271 | break; |
| 272 | |
| 273 | // if we timed out and there isn't any work to do then |
| 274 | // this thread will quit this loop and end. |
| 275 | if (self.data_ready.wait_or_timeout(DLIB_THREAD_POOL_TIMEOUT) == false && |
| 276 | self.function_pointer == 0) |
| 277 | break; |
| 278 | |
| 279 | } |
nothing calls this directly
no test coverage detected