| 568 | } |
| 569 | |
| 570 | int bthread_key_create2(bthread_key_t* key, |
| 571 | void (*dtor)(void*, const void*), |
| 572 | const void* dtor_args) { |
| 573 | uint32_t index = 0; |
| 574 | { |
| 575 | BAIDU_SCOPED_LOCK(bthread::s_key_mutex); |
| 576 | if (bthread::nfreekey > 0) { |
| 577 | index = bthread::s_free_keys[--bthread::nfreekey]; |
| 578 | } else if (bthread::nkey < bthread::KEYS_MAX) { |
| 579 | index = bthread::nkey++; |
| 580 | } else { |
| 581 | return EAGAIN; // what pthread_key_create returns in this case. |
| 582 | } |
| 583 | } |
| 584 | bthread::s_key_info[index].dtor = dtor; |
| 585 | bthread::s_key_info[index].dtor_args = dtor_args; |
| 586 | key->index = index; |
| 587 | key->version = bthread::s_key_info[index].version; |
| 588 | if (key->version == 0) { |
| 589 | ++bthread::s_key_info[index].version; |
| 590 | ++key->version; |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | int bthread_key_create(bthread_key_t* key, void (*dtor)(void*)) { |
| 596 | if (dtor == NULL) { |
no outgoing calls
no test coverage detected