| 323 | const int ID_MAX_RANGE = 1024; |
| 324 | |
| 325 | static int id_create_impl( |
| 326 | bthread_id_t* id, void* data, |
| 327 | int (*on_error)(bthread_id_t, void*, int), |
| 328 | int (*on_error2)(bthread_id_t, void*, int, const std::string&)) { |
| 329 | IdResourceId slot; |
| 330 | Id* const meta = get_resource(&slot); |
| 331 | if (meta) { |
| 332 | meta->data = data; |
| 333 | meta->on_error = on_error; |
| 334 | meta->on_error2 = on_error2; |
| 335 | CHECK(meta->pending_q.empty()); |
| 336 | uint32_t* butex = meta->butex; |
| 337 | if (0 == *butex || *butex + ID_MAX_RANGE + 2 < *butex) { |
| 338 | // Skip 0 so that bthread_id_t is never 0 |
| 339 | // avoid overflow to make comparisons simpler. |
| 340 | *butex = 1; |
| 341 | } |
| 342 | *meta->join_butex = *butex; |
| 343 | meta->first_ver = *butex; |
| 344 | meta->locked_ver = *butex + 1; |
| 345 | *id = make_id(*butex, slot); |
| 346 | return 0; |
| 347 | } |
| 348 | return ENOMEM; |
| 349 | } |
| 350 | |
| 351 | static int id_create_ranged_impl( |
| 352 | bthread_id_t* id, void* data, |
no test coverage detected