| 167 | // ------------------------------------------------------------------------------------ |
| 168 | |
| 169 | bool threader:: |
| 170 | create_new_thread ( |
| 171 | void (*funct)(void*), |
| 172 | void* param |
| 173 | ) |
| 174 | { |
| 175 | |
| 176 | // get a lock on the data mutex |
| 177 | auto_mutex M(data_mutex); |
| 178 | |
| 179 | // loop to ensure that the new function pointer is in the data |
| 180 | while (true) |
| 181 | { |
| 182 | // if the data is empty then add new data and quit loop |
| 183 | if (function_pointer == 0) |
| 184 | { |
| 185 | parameter = param; |
| 186 | function_pointer = funct; |
| 187 | break; |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | // wait for data to become empty |
| 192 | data_empty.wait(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | // get a thread for this new data |
| 198 | // if a new thread must be created |
| 199 | if (pool_count == 0) |
| 200 | { |
| 201 | // make thread and add it to the pool |
| 202 | if ( threads_kernel_shared_helpers::spawn_thread(thread_starter, this) == false ) |
| 203 | { |
| 204 | function_pointer = 0; |
| 205 | parameter = 0; |
| 206 | data_empty.signal(); |
| 207 | return false; |
| 208 | } |
| 209 | ++total_count; |
| 210 | } |
| 211 | // wake up a thread from the pool |
| 212 | else |
| 213 | { |
| 214 | data_ready.signal(); |
| 215 | } |
| 216 | |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | // ------------------------------------------------------------------------------------ |
| 221 |
nothing calls this directly
no test coverage detected