| 229 | } |
| 230 | |
| 231 | static lwpid_t |
| 232 | tid_alloc(void) |
| 233 | { |
| 234 | static lwpid_t trytid; |
| 235 | lwpid_t tid; |
| 236 | |
| 237 | mtx_lock(&tid_lock); |
| 238 | /* |
| 239 | * It is an invariant that the bitmap is big enough to hold maxthread |
| 240 | * IDs. If we got to this point there has to be at least one free. |
| 241 | */ |
| 242 | if (trytid >= maxthread) |
| 243 | trytid = 0; |
| 244 | bit_ffc_at(tid_bitmap, trytid, maxthread, &tid); |
| 245 | if (tid == -1) { |
| 246 | KASSERT(trytid != 0, ("unexpectedly ran out of IDs")); |
| 247 | trytid = 0; |
| 248 | bit_ffc_at(tid_bitmap, trytid, maxthread, &tid); |
| 249 | KASSERT(tid != -1, ("unexpectedly ran out of IDs")); |
| 250 | } |
| 251 | bit_set(tid_bitmap, tid); |
| 252 | trytid = tid + 1; |
| 253 | mtx_unlock(&tid_lock); |
| 254 | return (tid + NO_PID); |
| 255 | } |
| 256 | |
| 257 | static void |
| 258 | tid_free_locked(lwpid_t rtid) |
no test coverage detected