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

Function bthread_id_trylock

src/bthread/id.cpp:538–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

536}
537
538int bthread_id_trylock(bthread_id_t id, void** pdata) {
539 bthread::Id* const meta = address_resource(bthread::get_slot(id));
540 if (!meta) {
541 return EINVAL;
542 }
543 uint32_t* butex = meta->butex;
544 const uint32_t id_ver = bthread::get_version(id);
545 meta->mutex.lock();
546 if (!meta->has_version(id_ver)) {
547 meta->mutex.unlock();
548 return EINVAL;
549 }
550 if (*butex != meta->first_ver) {
551 meta->mutex.unlock();
552 return EBUSY;
553 }
554 *butex = meta->locked_ver;
555 meta->mutex.unlock();
556 if (pdata != NULL) {
557 *pdata = meta->data;
558 }
559 return 0;
560}
561
562int bthread_id_lock_verbose(bthread_id_t id, void** pdata,
563 const char *location) {

Callers 4

signallerFunction · 0.85
TESTFunction · 0.85
FightAuthenticationMethod · 0.85
EndWaitMethod · 0.85

Calls 5

get_slotFunction · 0.70
get_versionFunction · 0.70
address_resourceFunction · 0.50
lockMethod · 0.45
unlockMethod · 0.45

Tested by 2

signallerFunction · 0.68
TESTFunction · 0.68