MCPcopy Create free account
hub / github.com/apache/brpc / bthread_key_create2

Function bthread_key_create2

src/bthread/key.cpp:570–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570int 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
595int bthread_key_create(bthread_key_t* key, void (*dtor)(void*)) {
596 if (dtor == NULL) {

Callers 2

StartInternalMethod · 0.85
bthread_key_createFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected